From 5a8eca90e4ca997cb6ae9029e23579baaf93de27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20K=C5=82opotek=20-=20INTERDUO?= Date: Tue, 24 Feb 2026 12:11:26 +0100 Subject: [PATCH 1/2] devel: consolidate php variadic function calls when it is possible --- bin/lms-payments.php | 4 +- bin/lms-pna.php | 2 +- bin/lms-teryt.php | 2 +- devel/refactor_php_variadic_functions.php | 389 ++++++++++++++++++ lib/KSeF/KSeF.php | 6 +- lib/LMSManagers/LMSCashManager.php | 2 +- lib/LMSManagers/LMSConfigManager.php | 10 +- lib/LMSManagers/LMSCustomerManager.php | 2 +- lib/LMSManagers/LMSFinanceManager.php | 4 +- lib/LMSManagers/LMSNetDevManager.php | 4 +- lib/SmartyPlugins/LMSSmartyPlugins.php | 8 +- lib/SmartyPlugins/function.js.php | 2 +- lib/SmartyPlugins/function.list.php | 2 +- .../function.persistent_filter.php | 2 +- lib/Utils.php | 2 +- lib/customercontacttypes.php | 2 +- modules/archiveinfo.php | 2 +- modules/archiveview.php | 2 +- modules/chooselocation.php | 4 +- modules/choosenetdevmodel.php | 2 +- modules/configedit.php | 2 +- modules/configexport.php | 4 +- modules/customeredit.php | 2 +- modules/document.inc.php | 8 +- modules/documentadd.php | 2 +- modules/documentgen.php | 6 +- modules/documentsend.php | 2 +- modules/eventadd.php | 6 +- modules/eventlist.php | 4 +- modules/eventschedule.php | 4 +- modules/invoicearchive.php | 2 +- modules/invoicenote.php | 2 +- modules/invoicenoteedit.php | 2 +- modules/invoicesend.php | 2 +- modules/invoiceunarchive.php | 2 +- modules/messageadd.php | 2 +- modules/netdevadd.php | 2 +- modules/netdevmodels.php | 2 +- modules/netedit.php | 2 +- modules/netnodeadd.php | 2 +- modules/netnodeedit.php | 2 +- modules/netusage.php | 2 +- modules/nodeadd.php | 2 +- modules/quicksearch.php | 2 +- modules/receiptadd.php | 4 +- modules/reload.php | 6 +- modules/rtmessageadd.php | 2 +- modules/rtticketadd.php | 2 +- modules/rtticketview.php | 2 +- modules/traffic/actions/traffic.php | 2 +- modules/ukepit.php | 4 +- 51 files changed, 466 insertions(+), 77 deletions(-) create mode 100644 devel/refactor_php_variadic_functions.php 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/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) : '') . '>