diff --git a/bin/lms-payments.php b/bin/lms-payments.php index 10457ed0a3..b85079cc62 100755 --- a/bin/lms-payments.php +++ b/bin/lms-payments.php @@ -1633,7 +1633,7 @@ function GetBillingTemplates($document_dirs) $desc = str_replace('%aligned_partial_period', $first_aligned_partial_period[$p], $desc); unset($first_aligned_partial_period); } else { - if (isset($dateto) && isset($dateto_nextday) && intval($dateto_nextday[2]) != 1 && intval($dateto[1]) == intval($month) && intval($dateto[0]) == intval($year)) { + if (isset($dateto, $dateto_nextday) && intval($dateto_nextday[2]) != 1 && intval($dateto[1]) == intval($month) && intval($dateto[0]) == intval($year)) { $last_aligned_partial_period = array( DAILY => $forward_periods[DAILY], WEEKLY => $forward_periods[WEEKLY], @@ -1663,7 +1663,7 @@ function GetBillingTemplates($document_dirs) $desc = str_replace('%aligned_partial_period', $first_aligned_partial_period[$p], $desc); unset($first_aligned_partial_period); } else { - if (isset($dateto) && isset($dateto_nextday) && intval($dateto_nextday[2]) != 1 && intval($dateto[1]) == intval($backward_month) && intval($dateto[0]) == intval($backward_year)) { + if (isset($dateto, $dateto_nextday) && intval($dateto_nextday[2]) != 1 && intval($dateto[1]) == intval($backward_month) && intval($dateto[0]) == intval($backward_year)) { $last_aligned_partial_period = array( DAILY => $forward_periods[DAILY], WEEKLY => $forward_periods[WEEKLY], diff --git a/bin/lms-pna.php b/bin/lms-pna.php index b194a4074d..ac49d1aa2f 100755 --- a/bin/lms-pna.php +++ b/bin/lms-pna.php @@ -498,7 +498,7 @@ function convert_pna_to_teryt($data) } $state = $all_states[$state_name]; if (preg_match('/^[0-9]{2}-[0-9]{3}$/', $data[PNA]) - && (!isset($state_list) || (isset($state_list) && isset($state_list[$state])))) { + && (!isset($state_list) || (isset($state_list, $state_list[$state])))) { convert_pna_to_teryt($data); } } diff --git a/bin/lms-teryt.php b/bin/lms-teryt.php index 16c4c02fb4..fb27b64119 100755 --- a/bin/lms-teryt.php +++ b/bin/lms-teryt.php @@ -1644,7 +1644,7 @@ function stream_notification_callback($notification_code, $severity, $message, $ if ($building) { $fields_to_update = array(); - if (isset($record['gml_id']) && $record['gml_id'] != $building['extid'] || !isset($record['gml_id']) && isset($record['extid']) && strlen($record['extid'])) { + if (isset($record['gml_id']) && $record['gml_id'] != $building['extid'] || !isset($record['gml_id'], $record['extid']) && strlen($record['extid'])) { $fields_to_update[] = 'extid = ' . (isset($record['gml_id']) ? $DB->Escape($record['gml_id']) : 'null'); } diff --git a/devel/refactor_php_variadic_functions.php b/devel/refactor_php_variadic_functions.php new file mode 100644 index 0000000000..e545e33335 --- /dev/null +++ b/devel/refactor_php_variadic_functions.php @@ -0,0 +1,389 @@ + isset($a, $b) + * 2. Standalone consecutive: var_dump($a); var_dump($b); => var_dump($a, $b); + * 3. Target consecutive: array_push($x, $a); array_push($x, $b); => array_push($x, $a, $b); + * 4. Reassignment: $x = array_merge($x, $a); $x = array_merge($x, $b); => $x = array_merge($x, $a, $b); + * + * Usage: + * php refactor_php_variadic_functions.php [--dry-run] + */ + +if ($argc < 2) { + die("Usage: php refactor_php_variadic_functions.php [--dry-run]\n"); +} + +$path = $argv[1]; +$dryRun = in_array('--dry-run', $argv); +$ignoredDirs = ['vendor', '.git', 'node_modules']; + +// ----------------------- Zbieranie plików ----------------------- +$files = []; + +if (is_file($path) && substr($path, -4) === '.php') { + $files[] = $path; +} else { + $iterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS) + ); + foreach ($iterator as $file) { + $filePath = $file->getPathname(); + foreach ($ignoredDirs as $dir) { + if (strpos($filePath, DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR) !== false) { + continue 2; + } + } + if (substr($filePath, -4) === '.php') { + $files[] = $filePath; + } + } +} + +// ----------------------- Klasyfikacja Funkcji ----------------------- +$funcsChained = ['isset']; // && +$funcsStandalone = ['var_dump', 'compact']; +$funcsTarget = ['array_push', 'array_unshift', 'array_multisort']; // same first arg +$funcsReassign = ['array_merge', 'array_merge_recursive', 'array_intersect', 'array_intersect_assoc', + 'array_intersect_key', 'array_diff', 'array_diff_assoc', 'array_diff_key', 'max', 'min']; // $x = func($x, ...) + +// ----------------------- Helpery Tokenów ----------------------- +function getTokenValue($t) +{ + return is_string($t) ? $t : $t[1]; +} + +function skipWhitespaceAndComments($tokens, &$idx, $count) +{ + while ($idx < $count && is_array($tokens[$idx]) && in_array($tokens[$idx][0], [T_WHITESPACE, T_COMMENT, T_DOC_COMMENT])) { + $idx++; + } +} + +function parseFunctionCall($tokens, $startIdx, $count) +{ + $idx = $startIdx; + $idx++; // skip function name token + skipWhitespaceAndComments($tokens, $idx, $count); + if ($idx >= $count || getTokenValue($tokens[$idx]) !== '(') { + return null; + } + $idx++; // skip '(' + + $args = []; + $currentArg = []; + $parenDepth = 1; + + while ($idx < $count) { + $t = $tokens[$idx]; + $tval = getTokenValue($t); + + if ($tval === '(') { + $parenDepth++; + } + if ($tval === ')') { + $parenDepth--; + if ($parenDepth === 0) { + if (!empty($currentArg)) { + $args[] = $currentArg; + } + $idx++; // consume ')' + return ['args' => $args, 'endIdx' => $idx]; + } + } + + if ($parenDepth === 1 && $tval === ',') { + $args[] = $currentArg; + $currentArg = []; + } else { + // strip leading space of args if they are purely leading space + if (empty($currentArg) && is_array($t) && $t[0] == T_WHITESPACE && strpos($tval, "\n") === false) { + // skip leading inline whitespace + } else { + $currentArg[] = $t; + } + } + $idx++; + } + return null; +} + +function compareTokens($tokensA, $tokensB) +{ + if (count($tokensA) !== count($tokensB)) { + return false; + } + foreach ($tokensA as $i => $ta) { + if (getTokenValue($ta) !== getTokenValue($tokensB[$i])) { + return false; + } + } + return true; +} + +// ----------------------- Przetwarzanie ----------------------- +foreach ($files as $filePath) { + $source = file_get_contents($filePath); + $tokens = token_get_all($source); + $count = count($tokens); + $newSource = ''; + $i = 0; + $modified = false; + + while ($i < $count) { + $t = $tokens[$i]; + $tval = getTokenValue($t); + + // 1. Chained ISSET (i inne łączone logicznie) + if (is_array($t) && ($t[0] == T_ISSET || (in_array(strtolower($tval), $funcsChained) && $t[0] == T_STRING))) { + $funcName = is_array($t) && $t[0] == T_ISSET ? 'isset' : $tval; + $call = parseFunctionCall($tokens, $i, $count); + + if ($call !== null) { + $consolidatedArgs = $call['args']; + $idx = $call['endIdx']; + $hasChain = false; + + while ($idx < $count) { + $tempIdx = $idx; + skipWhitespaceAndComments($tokens, $tempIdx, $count); + + if ($tempIdx < $count && is_array($tokens[$tempIdx]) && in_array($tokens[$tempIdx][0], [T_BOOLEAN_AND, T_LOGICAL_AND])) { + $tempIdx++; // skip && + skipWhitespaceAndComments($tokens, $tempIdx, $count); + + $nextT = $tokens[$tempIdx]; + $nextTval = getTokenValue($nextT); + $isNextMatch = false; + if ($funcName === 'isset' && is_array($nextT) && $nextT[0] == T_ISSET) { + $isNextMatch = true; + } + if ($funcName !== 'isset' && is_array($nextT) && $nextT[0] == T_STRING && strtolower($nextTval) === strtolower($funcName)) { + $isNextMatch = true; + } + + if ($isNextMatch) { + $nextCall = parseFunctionCall($tokens, $tempIdx, $count); + if ($nextCall !== null) { + foreach ($nextCall['args'] as $a) { + $consolidatedArgs[] = $a; + } + $idx = $nextCall['endIdx']; + $hasChain = true; + continue; + } + } + } + break; + } + + if ($hasChain) { + $modified = true; + $newSource .= $funcName . '('; + foreach ($consolidatedArgs as $k => $arg) { + if ($k > 0) { + $newSource .= ', '; + } + foreach ($arg as $at) { + $newSource .= getTokenValue($at); + } + } + $newSource .= ')'; + $i = $idx; + continue; + } + } + } + + // Zapisz normalny token + $newSource .= $tval; + $i++; + } + + // Drugi przebieg - sekwencje instrukcji (Sequential Statements) + if ($modified) { + $tokens = token_get_all($newSource); + $count = count($tokens); + } + + $finalSource = ''; + $i = 0; + $seqModified = false; + + while ($i < $count) { + // Look for statements like: var_dump(...); or array_push($a, ...); or $a = array_merge($a, ...); + $t = $tokens[$i]; + + // Match assignment: $var = func(...) ; + $assignVar = null; + $tempIdx = $i; + if (is_array($t) && $t[0] == T_VARIABLE) { + $assignVarStr = getTokenValue($t); + $assignVarTokens = [$t]; + $tempIdx++; + skipWhitespaceAndComments($tokens, $tempIdx, $count); + // could have array dim $a['b'] = func + while ($tempIdx < $count && (getTokenValue($tokens[$tempIdx]) === '[' || is_array($tokens[$tempIdx]))) { + if (getTokenValue($tokens[$tempIdx]) === '=') { + break; + } + $assignVarTokens[] = $tokens[$tempIdx]; + $tempIdx++; + } + if ($tempIdx < $count && getTokenValue($tokens[$tempIdx]) === '=') { + $tempIdx++; + skipWhitespaceAndComments($tokens, $tempIdx, $count); + if ($tempIdx < $count && is_array($tokens[$tempIdx]) && $tokens[$tempIdx][0] == T_STRING) { + $assignVar = $assignVarTokens; + } + } + } + + $funcStartIdx = $assignVar ? $tempIdx : $i; + $funcT = $tokens[$funcStartIdx]; + + if (is_array($funcT) && $funcT[0] == T_STRING) { + $funcName = strtolower(getTokenValue($funcT)); + + $isStandalone = in_array($funcName, $funcsStandalone) && !$assignVar; + $isTarget = in_array($funcName, $funcsTarget) && !$assignVar; + $isReassign = in_array($funcName, $funcsReassign) && $assignVar; + + if ($isStandalone || $isTarget || $isReassign) { + $call = parseFunctionCall($tokens, $funcStartIdx, $count); + + if ($call !== null) { + $endIdx = $call['endIdx']; + skipWhitespaceAndComments($tokens, $endIdx, $count); + + if ($endIdx < $count && getTokenValue($tokens[$endIdx]) === ';') { + $endIdx++; // skip ';' + + $isValidFirstCall = true; + $targetArg = null; + + if ($isTarget || $isReassign) { + if (count($call['args']) < 1) { + $isValidFirstCall = false; + } else { + $targetArg = $call['args'][0]; + } + + if ($isReassign && $isValidFirstCall) { + if (!compareTokens($assignVar, $targetArg)) { + $isValidFirstCall = false; + } + } + } + + if ($isValidFirstCall) { + $consolidatedArgs = $call['args']; + $hasSequence = false; + $idx = $endIdx; + + while ($idx < $count) { + $scanIdx = $idx; + skipWhitespaceAndComments($tokens, $scanIdx, $count); + + // check assignment match + $nextAssignVar = null; + if ($isReassign) { + $nextAssignTokens = []; + while ($scanIdx < $count && getTokenValue($tokens[$scanIdx]) !== '=') { + if (!in_array(is_array($tokens[$scanIdx]) ? $tokens[$scanIdx][0] : '', [T_WHITESPACE, T_COMMENT, T_DOC_COMMENT])) { + $nextAssignTokens[] = $tokens[$scanIdx]; + } + $scanIdx++; + } + if ($scanIdx < $count && getTokenValue($tokens[$scanIdx]) === '=') { + $nextAssignVar = $nextAssignTokens; + $scanIdx++; + skipWhitespaceAndComments($tokens, $scanIdx, $count); + } + } + + if ($scanIdx < $count && is_array($tokens[$scanIdx]) && $tokens[$scanIdx][0] == T_STRING && strtolower(getTokenValue($tokens[$scanIdx])) === $funcName) { + $nextCall = parseFunctionCall($tokens, $scanIdx, $count); + + if ($nextCall !== null) { + $nextEndIdx = $nextCall['endIdx']; + skipWhitespaceAndComments($tokens, $nextEndIdx, $count); + + if ($nextEndIdx < $count && getTokenValue($tokens[$nextEndIdx]) === ';') { + $nextEndIdx++; // skip ';' + + $isValidNext = true; + if ($isTarget || $isReassign) { + if (count($nextCall['args']) < 1) { + $isValidNext = false; + } else if (!compareTokens($targetArg, $nextCall['args'][0])) { + $isValidNext = false; + } + } + if ($isReassign && $isValidNext) { + if (!compareTokens($assignVar, $nextAssignVar)) { + $isValidNext = false; + } + } + + if ($isValidNext) { + $argsToAdd = $nextCall['args']; + if ($isTarget || $isReassign) { + array_shift($argsToAdd); // drop the target arg + } + foreach ($argsToAdd as $a) { + $consolidatedArgs[] = $a; + } + + $hasSequence = true; + $idx = $nextEndIdx; + continue; + } + } + } + } + break; + } + + if ($hasSequence) { + $seqModified = true; + if ($assignVar) { + foreach ($assignVar as $at) { + $finalSource .= getTokenValue($at); + } + $finalSource .= ' = '; + } + $finalSource .= $tokenIdToName = getTokenValue($funcT) . '('; + foreach ($consolidatedArgs as $k => $arg) { + if ($k > 0) { + $finalSource .= ', '; + } + foreach ($arg as $at) { + $finalSource .= getTokenValue($at); + } + } + $finalSource .= ');'; + $i = $idx; + continue; + } + } + } + } + } + } + + $finalSource .= getTokenValue($t); + $i++; + } + + if ($modified || $seqModified) { + $outSource = $seqModified ? $finalSource : $newSource; + if ($dryRun) { + echo "Would change: $filePath\n"; + } else { + file_put_contents($filePath, $outSource); + echo "Changed: $filePath\n"; + } + } +} diff --git a/devel/refactor_smarty_assign_using_array.php b/devel/refactor_smarty_assign_using_array.php new file mode 100644 index 0000000000..dfd481a97d --- /dev/null +++ b/devel/refactor_smarty_assign_using_array.php @@ -0,0 +1,304 @@ +\n"); +} + +$target = $argv[1]; + +function getTokens($source) +{ + return token_get_all($source); +} + +function processFile($filePath) +{ + echo "Processing: $filePath\n"; + $source = file_get_contents($filePath); + $tokens = token_get_all($source); + + $newSource = ''; + $count = count($tokens); + $i = 0; + + $modified = false; + + while ($i < $count) { + // Look for $SMARTY->assign( + // Expected sequence: T_VARIABLE ($SMARTY) -> T_OBJECT_OPERATOR (->) -> T_STRING (assign) -> ( + + $matchFound = false; + + // Check if we are at start of a potential assign block + if (is_array($tokens[$i]) && $tokens[$i][0] == T_VARIABLE && $tokens[$i][1] == '$SMARTY') { + // Check ahead for -> assign ( + $j = $i + 1; + while ($j < $count && is_array($tokens[$j]) && $tokens[$j][0] == T_WHITESPACE) { + $j++; // skip whitespace + } + + if ($j < $count && is_array($tokens[$j]) && $tokens[$j][0] == T_OBJECT_OPERATOR) { + $j++; + while ($j < $count && is_array($tokens[$j]) && $tokens[$j][0] == T_WHITESPACE) { + $j++; // skip whitespace + } + + if ($j < $count && is_array($tokens[$j]) && $tokens[$j][0] == T_STRING && $tokens[$j][1] == 'assign') { + $j++; + while ($j < $count && is_array($tokens[$j]) && $tokens[$j][0] == T_WHITESPACE) { + $j++; // skip whitespace + } + + if ($j < $count && $tokens[$j] == '(') { + // Found valid $SMARTY->assign( start + + // Now we need to collect this assignment and any immediately following ones + $assignments = []; + $currentStart = $i; + + // Parsing loop to collect consecutive assignments + while (true) { + // Check if this is a $SMARTY->assign call + // Rewind slightly logic wise: we are essentially attempting to parse one full statement here + // We need to verify it is exactly $SMARTY->assign('key', $val); + + // Re-verify the sequence for the current potential assignment (since we loop) + $tempJ = $currentStart; + + // Skip whitespace + while ($tempJ < $count && is_array($tokens[$tempJ]) && $tokens[$tempJ][0] == T_WHITESPACE) { + $tempJ++; + } + + // Must be $SMARTY + if (!($tempJ < $count && is_array($tokens[$tempJ]) && $tokens[$tempJ][0] == T_VARIABLE && $tokens[$tempJ][1] == '$SMARTY')) { + break; + } + $tempJ++; + + while ($tempJ < $count && is_array($tokens[$tempJ]) && $tokens[$tempJ][0] == T_WHITESPACE) { + $tempJ++; + } + if (!($tempJ < $count && is_array($tokens[$tempJ]) && $tokens[$tempJ][0] == T_OBJECT_OPERATOR)) { + break; + } + $tempJ++; + + while ($tempJ < $count && is_array($tokens[$tempJ]) && $tokens[$tempJ][0] == T_WHITESPACE) { + $tempJ++; + } + if (!($tempJ < $count && is_array($tokens[$tempJ]) && $tokens[$tempJ][0] == T_STRING && $tokens[$tempJ][1] == 'assign')) { + break; + } + $tempJ++; + + while ($tempJ < $count && is_array($tokens[$tempJ]) && $tokens[$tempJ][0] == T_WHITESPACE) { + $tempJ++; + } + if (!($tempJ < $count && $tokens[$tempJ] == '(')) { + break; + } + $openParenPos = $tempJ; + $tempJ++; + + // Now extraction of arguments: key and value + // We only support simple string keys: 'key' or "key" + // Value can be complex expression, UP TO the comma + + while ($tempJ < $count && is_array($tokens[$tempJ]) && $tokens[$tempJ][0] == T_WHITESPACE) { + $tempJ++; + } + + $keyTokens = []; + if ($tempJ < $count && is_array($tokens[$tempJ]) && $tokens[$tempJ][0] == T_CONSTANT_ENCAPSED_STRING) { + $keyTokens[] = $tokens[$tempJ]; + $tempJ++; + } else { + // First arg is not a simple string, abort this block logic + break; + } + + while ($tempJ < $count && is_array($tokens[$tempJ]) && $tokens[$tempJ][0] == T_WHITESPACE) { + $tempJ++; + } + + if (!($tempJ < $count && $tokens[$tempJ] == ',')) { + // Only one argument? or "assign by ref"? ignored + break; + } + $tempJ++; // consume comma + + // Now capturing value until ); + // Careful with nested parens + + $valueTokens = []; + $parenDepth = 1; // We are inside assign( ... + + while ($tempJ < $count) { + $t = $tokens[$tempJ]; + if ($t == '(') { + $parenDepth++; + } elseif ($t == ')') { + $parenDepth--; + } + + if ($parenDepth == 0) { + // Found closing paren of assign(...) + break; + } + + $valueTokens[] = $t; + $tempJ++; + } + + if ($parenDepth != 0) { + break; // formatting error or weirdness + } + + $closeParenPos = $tempJ; + $tempJ++; // consume ) + + while ($tempJ < $count && is_array($tokens[$tempJ]) && $tokens[$tempJ][0] == T_WHITESPACE) { + $tempJ++; + } + + if (!($tempJ < $count && $tokens[$tempJ] == ';')) { + // Not a simple statement ending with ; + break; + } + $semiColonPos = $tempJ; + $tempJ++; // consume ; + + // Success finding one assignment + $assignments[] = [ + 'key' => $keyTokens, + 'value' => $valueTokens, + 'end_pos' => $tempJ // exclusive + ]; + + // Prepare to look for next + $currentStart = $tempJ; + } + + if (count($assignments) > 1) { + // We found consecutive assignments! + // Write replacement + $matchFound = true; + + // Check indentation of the first variable to try to preserve it + // We can look at whitespace immediately preceding $i if any + $baseIndent = ""; + if ($i > 0 && is_array($tokens[$i - 1]) && $tokens[$i - 1][0] == T_WHITESPACE) { + $ws = $tokens[$i - 1][1]; + $pos = strrpos($ws, "\n"); + if ($pos !== false) { + $baseIndent = substr($ws, $pos + 1); + } else { + $baseIndent = $ws; + } + } + + $indentUnit = (strpos($baseIndent, "\t") !== false) ? "\t" : " "; + $twoIndents = $indentUnit . $indentUnit; + + $newSource .= "\$SMARTY->assign(\n"; + $newSource .= $baseIndent . $indentUnit . "array(\n"; + + foreach ($assignments as $idx => $assign) { + $newSource .= $baseIndent . $twoIndents; // indent + // Key + foreach ($assign['key'] as $kt) { + $newSource .= is_array($kt) ? $kt[1] : $kt; + } + $newSource .= " => "; + // Value - process token by token + $isFirstValueToken = true; + $valueOutput = ''; + foreach ($assign['value'] as $vt) { + $isWhitespace = is_array($vt) && $vt[0] == T_WHITESPACE; + $tokenValue = is_array($vt) ? $vt[1] : $vt; + + if ($isFirstValueToken) { + // Strip only leading horizontal whitespace (spaces/tabs), not newlines + $tokenValue = ltrim($tokenValue, " \t"); + if ($tokenValue === '') { + continue; + } + $isFirstValueToken = false; + } + + // Only modify whitespace tokens, never string content + if ($isWhitespace && strpos($tokenValue, "\n") !== false) { + // Replace each newline + old indent with newline + shifted indent + $wsLines = explode("\n", $tokenValue); + for ($wl = 1; $wl < count($wsLines); $wl++) { + $wsLine = $wsLines[$wl]; + if ($indentUnit === "\t") { + $wsLine = str_replace(" ", "\t", $wsLine); + } + $wsLines[$wl] = $twoIndents . $wsLine; + } + $tokenValue = implode("\n", $wsLines); + } + + $valueOutput .= $tokenValue; + } + + // Clean trailing whitespace on each line of the final value + $valueLines = explode("\n", $valueOutput); + foreach ($valueLines as &$vLine) { + $vLine = rtrim($vLine); + } + $valueOutput = implode("\n", $valueLines); + + // If value starts with newline, trim trailing space from "=> " on the key line + if (strlen($valueOutput) > 0 && $valueOutput[0] === "\n") { + $newSource = rtrim($newSource); + } + + $newSource .= $valueOutput; + + $newSource .= ",\n"; + } + + $newSource .= $baseIndent . $indentUnit . ")\n"; + $newSource .= $baseIndent . ");"; + + // Advance main loop to end of last assignment + $i = $assignments[count($assignments)-1]['end_pos']; + $modified = true; + } else { + // Only 0 or 1 assignment found, not enough to merge, or structure wasn't perfect + // Just print the token at $i and move on normally + // We fall through to default printer + } + } + } + } + } + + if (!$matchFound && $i < $count) { + $token = $tokens[$i]; + $newSource .= is_array($token) ? $token[1] : $token; + $i++; + } + } + + if ($modified) { + file_put_contents($filePath, $newSource); + echo "Modified: $filePath\n"; + } +} + +if (is_dir($target)) { + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($target)); + foreach ($iterator as $file) { + if ($file->isFile() && $file->getExtension() === 'php') { + processFile($file->getPathname()); + } + } +} elseif (is_file($target)) { + processFile($target); +} else { + die("Invalid target.\n"); +} diff --git a/lib/KSeF/KSeF.php b/lib/KSeF/KSeF.php index 3d38a2d196..b8a1217c6f 100644 --- a/lib/KSeF/KSeF.php +++ b/lib/KSeF/KSeF.php @@ -453,7 +453,7 @@ public function getInvoiceXml(array $invoice) } else { $taxRate = null; } - if (isset($taxRate) && isset($invoice['taxest'][$taxRate])) { + if (isset($taxRate, $invoice['taxest'][$taxRate])) { $xml .= "\t\t" . sprintf('%.2f', $invoice['taxest'][$taxRate]['base']) . "" . PHP_EOL; $xml .= "\t\t" . sprintf('%.2f', $invoice['taxest'][$taxRate]['tax']) . "" . PHP_EOL; if ($currency != $this->defaultCurrency) { @@ -499,7 +499,7 @@ public function getInvoiceXml(array $invoice) } else { $taxRate = null; } - if (isset($taxRate) && isset($invoice['taxest'][$taxRate])) { + if (isset($taxRate, $invoice['taxest'][$taxRate])) { $xml .= "\t\t" . sprintf('%.2f', $invoice['taxest'][$taxRate]['base']) . "" . PHP_EOL; $xml .= "\t\t" . sprintf('%.2f', $invoice['taxest'][$taxRate]['tax']) . "" . PHP_EOL; if ($currency != $this->defaultCurrency) { @@ -541,7 +541,7 @@ public function getInvoiceXml(array $invoice) } else { $taxRate = null; } - if (isset($taxRate) && isset($invoice['taxest'][$taxRate])) { + if (isset($taxRate, $invoice['taxest'][$taxRate])) { $xml .= "\t\t" . sprintf('%.2f', $invoice['taxest'][$taxRate]['base']) . "" . PHP_EOL; $xml .= "\t\t" . sprintf('%.2f', $invoice['taxest'][$taxRate]['tax']) . "" . PHP_EOL; if ($currency != $this->defaultCurrency) { diff --git a/lib/LMSManagers/LMSCashManager.php b/lib/LMSManagers/LMSCashManager.php index 8ce203632e..7f47a031ba 100644 --- a/lib/LMSManagers/LMSCashManager.php +++ b/lib/LMSManagers/LMSCashManager.php @@ -667,7 +667,7 @@ public function CashImportParseFile($filename, $contents, $patterns, $quiet = tr if ($patterns_cnt && !empty($sum)) { foreach ($patterns as $idx => $pattern) { - if (isset($pattern['pattern_sum']) && isset($pattern['pattern_sum_check']) && !$pattern['pattern_sum_check']($data, $sum)) { + if (isset($pattern['pattern_sum'], $pattern['pattern_sum_check']) && !$pattern['pattern_sum_check']($data, $sum)) { $error['sum'] = true; } } diff --git a/lib/LMSManagers/LMSConfigManager.php b/lib/LMSManagers/LMSConfigManager.php index 9b20a8d369..7e40086410 100644 --- a/lib/LMSManagers/LMSConfigManager.php +++ b/lib/LMSManagers/LMSConfigManager.php @@ -246,7 +246,7 @@ public function DeleteConfigOption($id) private function globalConfigOptionExists($params) { extract($params); - if (isset($section) && isset($variable)) { + if (isset($section, $variable)) { return $this->db->GetOne( 'SELECT id FROM uiconfig WHERE section = ? AND var = ? AND divisionid IS NULL AND userid IS NULL', array($section, $variable) @@ -259,7 +259,7 @@ private function globalConfigOptionExists($params) private function divisionConfigOptionExists($params) { extract($params); - if (isset($section) && isset($variable) && isset($divisionid)) { + if (isset($section, $variable, $divisionid)) { return $this->db->GetOne( 'SELECT id FROM uiconfig WHERE section = ? AND var = ? AND divisionid = ? AND userid IS NULL', array($section, $variable, $divisionid) @@ -272,7 +272,7 @@ private function divisionConfigOptionExists($params) private function divisionUserConfigOptionExists($params) { extract($params); - if (isset($section) && isset($variable) && isset($divisionid) && isset($userid)) { + if (isset($section, $variable, $divisionid, $userid)) { return $this->db->GetOne( 'SELECT id FROM uiconfig WHERE section = ? AND var = ? AND divisionid = ? AND userid = ?', array($section, $variable, $divisionid, $userid) @@ -285,7 +285,7 @@ private function divisionUserConfigOptionExists($params) private function userConfigOptionExists($params) { extract($params); - if (isset($section) && isset($variable) && isset($userid)) { + if (isset($section, $variable, $userid)) { return $this->db->GetOne( 'SELECT id FROM uiconfig WHERE section = ? AND var = ? AND userid = ? AND divisionid IS NULL', array($section, $variable, $userid) @@ -1587,7 +1587,7 @@ private function overrideConfigOption($option) $args['value'] = $option['value']; $args['id'] = $id; - if (isset($args['description']) && isset($args['disabled']) && isset($args['type'])) { + if (isset($args['description'], $args['disabled'], $args['type'])) { $option_edited = $this->db->Execute( 'UPDATE uiconfig SET description = ?, disabled = ?, type = ?, value = ? WHERE id = ?', diff --git a/lib/LMSManagers/LMSCustomerManager.php b/lib/LMSManagers/LMSCustomerManager.php index 6ac561b9ea..9579b86105 100644 --- a/lib/LMSManagers/LMSCustomerManager.php +++ b/lib/LMSManagers/LMSCustomerManager.php @@ -2467,7 +2467,7 @@ public function GetCustomer($id, $short = false) $result['addresses'] = $this->getCustomerAddresses($result['id']); - $result['identity']['type'] = (isset($result['ict']) && isset($GLOBALS['IDENTITY_TYPES'][$result['ict']]) ? $GLOBALS['IDENTITY_TYPES'][$result['ict']] : 'ICN'); + $result['identity']['type'] = (isset($result['ict'], $GLOBALS['IDENTITY_TYPES'][$result['ict']]) ? $GLOBALS['IDENTITY_TYPES'][$result['ict']] : 'ICN'); $result['identity']['number'] = $result['icn']; $result['identity']['expires'] = $result['icexpires']; diff --git a/lib/LMSManagers/LMSFinanceManager.php b/lib/LMSManagers/LMSFinanceManager.php index c1882d88bb..5488932f44 100644 --- a/lib/LMSManagers/LMSFinanceManager.php +++ b/lib/LMSManagers/LMSFinanceManager.php @@ -1608,7 +1608,7 @@ public function ValidateAssignment($data) } } - if (isset($from) && isset($to)) { + if (isset($from, $to)) { if ($to < $from && $to != 0 && $from != 0) { $error['dateto'] = trans('Start date can\'t be greater than end date!'); } @@ -1814,7 +1814,7 @@ public function CheckSchemaModifiedValues(&$data) public function UpdateExistingAssignments($data) { - $refid = isset($data['reference']) && isset($data['existing_assignments']['reference_document_limit']) + $refid = isset($data['reference'], $data['existing_assignments']['reference_document_limit']) ? $data['reference'] : null; $assignment_type = $data['existing_assignments']['assignment_type_limit'] ?? null; diff --git a/lib/LMSManagers/LMSNetDevManager.php b/lib/LMSManagers/LMSNetDevManager.php index bbd07c7b5e..d9feaf27e6 100644 --- a/lib/LMSManagers/LMSNetDevManager.php +++ b/lib/LMSManagers/LMSNetDevManager.php @@ -240,7 +240,7 @@ public function SetNetDevLinkType($dev1, $dev2, $link = null) 'availablelines' => $availablelines, 'foreignentity' => $foreignentity, ); - if (isset($link['srcport']) && isset($link['dstport'])) { + if (isset($link['srcport'], $link['dstport'])) { $query .= ', srcport = ?, dstport = ?'; $args['srcport'] = intval($link['dstport']); $args['dstport'] = intval($link['srcport']); @@ -254,7 +254,7 @@ public function SetNetDevLinkType($dev1, $dev2, $link = null) if (!$res) { $args['src_' . SYSLOG::getResourceKey(SYSLOG::RES_RADIOSECTOR)] = $srcradiosector; $args['dst_' . SYSLOG::getResourceKey(SYSLOG::RES_RADIOSECTOR)] = $dstradiosector; - if (isset($link['srcport']) && isset($link['dstport'])) { + if (isset($link['srcport'], $link['dstport'])) { $args['srcport'] = intval($link['srcport']); $args['dstport'] = intval($link['dstport']); } diff --git a/lib/SmartyPlugins/LMSSmartyPlugins.php b/lib/SmartyPlugins/LMSSmartyPlugins.php index d2eac0d9e7..3c357807ce 100644 --- a/lib/SmartyPlugins/LMSSmartyPlugins.php +++ b/lib/SmartyPlugins/LMSSmartyPlugins.php @@ -126,7 +126,7 @@ public static function currencySelectionFunction(array $params, $template) { $elemid = isset($params['elemid']) ? 'id="' . $params['elemid'] . '"' : null; $elementname = $params['elementname'] ?? 'currency'; - $selected = isset($params['selected']) && isset($GLOBALS['CURRENCIES'][$params['selected']]) + $selected = isset($params['selected'], $GLOBALS['CURRENCIES'][$params['selected']]) ? $params['selected'] : null; $defaultSelected = Localisation::getCurrentCurrency(); $locked = isset($params['locked']) && $params['locked']; @@ -943,7 +943,7 @@ public static function tipFunction(array $params, $template) $class = ''; } $errors = $template->getTemplateVars('error'); - if (isset($params['trigger']) && isset($errors[$params['trigger']])) { + if (isset($params['trigger'], $errors[$params['trigger']])) { $error = str_replace("'", '\\\'', $errors[$params['trigger']]); $error = str_replace('"', '"', $error); $error = str_replace("\r", '', $error); @@ -953,7 +953,7 @@ public static function tipFunction(array $params, $template) $result .= ' class="' . (empty($class) ? '' : $class) . (isset($params['bold']) && $params['bold'] ? ' lms-ui-error bold" ' : ' lms-ui-error" '); } else { $warnings = $template->getTemplateVars('warning'); - if (isset($params['trigger']) && isset($warnings[$params['trigger']])) { + if (isset($params['trigger'], $warnings[$params['trigger']])) { $error = str_replace("'", '\\\'', $warnings[$params['trigger']]); $error = str_replace('"', '"', $error); $error = str_replace("\r", '', $error); @@ -1927,7 +1927,7 @@ public static function barCodeFunction($params, $template) $transliterate = !isset($params['transliterate']) || ConfigHelper::checkValue($params['transliterate']); $text = $params['text'] ?? 'text not set'; - $type = isset($params['type']) && isset($types[$params['type']]) ? $params['type'] : 'C128'; + $type = isset($params['type'], $types[$params['type']]) ? $params['type'] : 'C128'; $show_text = isset($params['show_text']) ? ConfigHelper::checkValue($params['show_text']) : true; $scale = isset($params['scale']) ? filter_var($params['scale'], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE) : null; if (!isset($scale)) { diff --git a/lib/SmartyPlugins/function.js.php b/lib/SmartyPlugins/function.js.php index 15ed2de2d5..c29fd7d317 100644 --- a/lib/SmartyPlugins/function.js.php +++ b/lib/SmartyPlugins/function.js.php @@ -26,7 +26,7 @@ function smarty_function_js(array $params, Smarty_Internal_Template $template) { - if (isset($params['plugin']) && isset($params['filename'])) { + if (isset($params['plugin'], $params['filename'])) { $filename = PLUGIN_DIR . DIRECTORY_SEPARATOR . $params['plugin'] . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . $params['filename']; if (file_exists($filename)) { diff --git a/lib/SmartyPlugins/function.list.php b/lib/SmartyPlugins/function.list.php index fe5e9b2337..499c6f9b85 100644 --- a/lib/SmartyPlugins/function.list.php +++ b/lib/SmartyPlugins/function.list.php @@ -72,7 +72,7 @@ function smarty_function_list(array $params, Smarty_Internal_Template $template) 'href' => '#', ), $template) . ' $tip, 'trigger' => $tipid), $template) : '') . '> + . (isset($tip, $tipid) ? smarty_function_tip(array('text' => $tip, 'trigger' => $tipid), $template) : '') . '>