diff options
author | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-11-05 21:19:01 +0300 |
---|---|---|
committer | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-11-05 21:19:01 +0300 |
commit | 6647365c78910fb45afa4784392f23b70997534a (patch) | |
tree | 5841201497f0a145537f41e9bc9ed49b5cfb0c3c | |
parent | c958e27bfaa3aae77353b6624206da0cb38b30af (diff) |
Refactor Display\Results::getOffsets() method
Improves type inference.
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
-rw-r--r-- | libraries/classes/Display/Results.php | 21 | ||||
-rw-r--r-- | psalm-baseline.xml | 11 |
2 files changed, 14 insertions, 18 deletions
diff --git a/libraries/classes/Display/Results.php b/libraries/classes/Display/Results.php index 12c1df39d4..49a4fc7fd9 100644 --- a/libraries/classes/Display/Results.php +++ b/libraries/classes/Display/Results.php @@ -50,6 +50,7 @@ use function implode; use function in_array; use function intval; use function is_array; +use function is_int; use function is_numeric; use function json_encode; use function max; @@ -3575,22 +3576,22 @@ class Results } /** - * Get offsets for next page and previous page + * Gets offsets for next page and previous page. * - * @see getTable() - * - * @return int[] array with two elements - $pos_next, $pos_prev + * @return array<int, int> + * @psalm-return array{int, int} */ - private function getOffsets() + private function getOffsets(): array { - if ($_SESSION['tmpval']['max_rows'] === self::ALL_ROWS) { + $tempVal = isset($_SESSION['tmpval']) && is_array($_SESSION['tmpval']) ? $_SESSION['tmpval'] : []; + if (isset($tempVal['max_rows']) && $tempVal['max_rows'] === self::ALL_ROWS) { return [0, 0]; } - return [ - $_SESSION['tmpval']['pos'] + $_SESSION['tmpval']['max_rows'], - max(0, $_SESSION['tmpval']['pos'] - $_SESSION['tmpval']['max_rows']), - ]; + $pos = isset($tempVal['pos']) && is_int($tempVal['pos']) ? $tempVal['pos'] : 0; + $maxRows = isset($tempVal['max_rows']) && is_int($tempVal['max_rows']) ? $tempVal['max_rows'] : 25; + + return [$pos + $maxRows, max(0, $pos - $maxRows)]; } /** diff --git a/psalm-baseline.xml b/psalm-baseline.xml index a58106e78c..8a88ab193f 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -6061,7 +6061,7 @@ <code>$sortExpression</code> <code>$urlParams</code> </MixedArgumentTypeCoercion> - <MixedArrayAccess occurrences="62"> + <MixedArrayAccess occurrences="60"> <code>$_SESSION['tmpval']['display_binary']</code> <code>$_SESSION['tmpval']['display_binary']</code> <code>$_SESSION['tmpval']['display_binary']</code> @@ -6092,8 +6092,6 @@ <code>$_SESSION['tmpval']['pos']</code> <code>$_SESSION['tmpval']['pos']</code> <code>$_SESSION['tmpval']['pos']</code> - <code>$_SESSION['tmpval']['pos']</code> - <code>$_SESSION['tmpval']['pos']</code> <code>$_SESSION['tmpval']['possible_as_geometry']</code> <code>$_SESSION['tmpval']['query']</code> <code>$_SESSION['tmpval']['query']</code> @@ -6252,12 +6250,10 @@ <code>new $className()</code> <code>new $this->transformationInfo[$dbLower][$tblLower][$nameLower][1]()</code> </MixedMethodCall> - <MixedOperand occurrences="11"> + <MixedOperand occurrences="9"> <code>$_SESSION['tmpval']['max_rows']</code> <code>$_SESSION['tmpval']['max_rows']</code> <code>$_SESSION['tmpval']['pos']</code> - <code>$_SESSION['tmpval']['pos']</code> - <code>$_SESSION['tmpval']['pos']</code> <code>$_SESSION['tmpval']['repeat_cells']</code> <code>$displayParams['rowdata'][$i][$rowNumber]</code> <code>$displaySize[0]</code> @@ -6275,10 +6271,9 @@ <code>$statementInfo->statement->from[0]->table</code> <code>$statementInfo->statement->limit->offset</code> </MixedPropertyFetch> - <MixedReturnTypeCoercion occurrences="6"> + <MixedReturnTypeCoercion occurrences="4"> <code>$map</code> <code>array<string, string[]></code> - <code>int[]</code> <code>string[]</code> </MixedReturnTypeCoercion> <PossiblyInvalidArgument occurrences="2"> |