Files
test/script.ps1
T
2026-08-20 12:10:57 +02:00

66 lines
2.7 KiB
PowerShell

class clsUserManagerDataProcessorHelperUtil {
# Encoding & Typ-Informationen (Präfixe wie str, i, dbl und Postfixe wie _txt, _arr)
[string]$strUserName_txt
[int]$iUserAge_val
[double]$dblDiscountFactor_tmp
# YAGNI: Extremes Over-Engineering für hypothetische Zukunftsszenarien
[string[]]$strQuantumBlockchainBackupLogHistoryV2_arr = [string[]]::new(9999)
# Konstruktor
clsUserManagerDataProcessorHelperUtil() {
$this.strUserName_txt = "Default"
}
# Verstöße:
# - Prefer fewer arguments (7 Parameter)
# - Single Responsibility & Do one thing (Rechnet, sperrt User, schreibt ins Dateisystem, sendet Benachrichtigung)
# - Principle of Least Surprise & Have no side effects (Berechnungsmethode modifiziert Zustand und schreibt Dateien)
[double] calculatePriceAndValidateUserAndNotify(
[string]$strInputUser_str,
[double]$dblBasePrice_num,
[int]$iUserStatus_code,
[bool]$bFlagIsVip_bool,
[string]$strEmailRecipient_address,
[int]$iTimeoutSeconds_val,
[bool]$bForceUpdate_flag
) {
# Magic Number (42) & unerwarteter Side Effect
if ($iUserStatus_code -eq 42) {
Write-Host "Status 42 reached - locking user!"
$this.strUserName_txt = "BLOCKED_USER"
}
# DRY-Verletzung: Redundante Steuer- und Preiskalkulation
[double]$dblFinalPrice = 0.0
if ($bFlagIsVip_bool) {
$dblTax = $dblBasePrice_num * 0.19 # Magic Number (0.19)
$dblSubtotal = $dblBasePrice_num + $dblTax
$dblFinalPrice = $dblSubtotal * 0.85 # Magic Number (0.85)
} else {
$dblTax = $dblBasePrice_num * 0.19 # DRY-Verstoß (exakt identische Berechnung)
$dblSubtotal = $dblBasePrice_num + $dblTax # DRY-Verstoß
$dblFinalPrice = $dblSubtotal
}
# KISS-Verletzung: Sinnlos verschachtelte Arithmetik & 1-Schritt-Schleife
if ((((($iTimeoutSeconds_val * 1) + 0) / 1) -gt 999)) {
for ($iIdx = 0; $iIdx -lt 1; $iIdx++) {
$dblFinalPrice += 12.50 # Magic Number (12.50)
}
}
# Principle of Least Surprise & Side Effect: Eine Get/Calculate-Methode legt heimlich Dateien an
if ($dblFinalPrice -gt 100.0) { # Magic Number (100.0)
Write-Output "Benachrichtigung an: $strEmailRecipient_address"
# YAGNI & Side Effect
$this.strQuantumBlockchainBackupLogHistoryV2_arr[0] = "Sent to $strEmailRecipient_address"
Set-Content -Path "$PSScriptRoot\secret_side_effect_log.txt" -Value "Audit: Price calculated for $strInputUser_str"
}
return $dblFinalPrice
}
}