Skip to content

Commit 6647365

Browse files
committed
Refactor Display\Results::getOffsets() method
Improves type inference. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent c958e27 commit 6647365

2 files changed

Lines changed: 14 additions & 18 deletions

File tree

libraries/classes/Display/Results.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
use function in_array;
5151
use function intval;
5252
use function is_array;
53+
use function is_int;
5354
use function is_numeric;
5455
use function json_encode;
5556
use function max;
@@ -3575,22 +3576,22 @@ public function getTable(
35753576
}
35763577

35773578
/**
3578-
* Get offsets for next page and previous page
3579+
* Gets offsets for next page and previous page.
35793580
*
3580-
* @see getTable()
3581-
*
3582-
* @return int[] array with two elements - $pos_next, $pos_prev
3581+
* @return array<int, int>
3582+
* @psalm-return array{int, int}
35833583
*/
3584-
private function getOffsets()
3584+
private function getOffsets(): array
35853585
{
3586-
if ($_SESSION['tmpval']['max_rows'] === self::ALL_ROWS) {
3586+
$tempVal = isset($_SESSION['tmpval']) && is_array($_SESSION['tmpval']) ? $_SESSION['tmpval'] : [];
3587+
if (isset($tempVal['max_rows']) && $tempVal['max_rows'] === self::ALL_ROWS) {
35873588
return [0, 0];
35883589
}
35893590

3590-
return [
3591-
$_SESSION['tmpval']['pos'] + $_SESSION['tmpval']['max_rows'],
3592-
max(0, $_SESSION['tmpval']['pos'] - $_SESSION['tmpval']['max_rows']),
3593-
];
3591+
$pos = isset($tempVal['pos']) && is_int($tempVal['pos']) ? $tempVal['pos'] : 0;
3592+
$maxRows = isset($tempVal['max_rows']) && is_int($tempVal['max_rows']) ? $tempVal['max_rows'] : 25;
3593+
3594+
return [$pos + $maxRows, max(0, $pos - $maxRows)];
35943595
}
35953596

35963597
/**

psalm-baseline.xml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6061,7 +6061,7 @@
60616061
<code>$sortExpression</code>
60626062
<code>$urlParams</code>
60636063
</MixedArgumentTypeCoercion>
6064-
<MixedArrayAccess occurrences="62">
6064+
<MixedArrayAccess occurrences="60">
60656065
<code>$_SESSION['tmpval']['display_binary']</code>
60666066
<code>$_SESSION['tmpval']['display_binary']</code>
60676067
<code>$_SESSION['tmpval']['display_binary']</code>
@@ -6092,8 +6092,6 @@
60926092
<code>$_SESSION['tmpval']['pos']</code>
60936093
<code>$_SESSION['tmpval']['pos']</code>
60946094
<code>$_SESSION['tmpval']['pos']</code>
6095-
<code>$_SESSION['tmpval']['pos']</code>
6096-
<code>$_SESSION['tmpval']['pos']</code>
60976095
<code>$_SESSION['tmpval']['possible_as_geometry']</code>
60986096
<code>$_SESSION['tmpval']['query']</code>
60996097
<code>$_SESSION['tmpval']['query']</code>
@@ -6252,12 +6250,10 @@
62526250
<code>new $className()</code>
62536251
<code>new $this-&gt;transformationInfo[$dbLower][$tblLower][$nameLower][1]()</code>
62546252
</MixedMethodCall>
6255-
<MixedOperand occurrences="11">
6253+
<MixedOperand occurrences="9">
62566254
<code>$_SESSION['tmpval']['max_rows']</code>
62576255
<code>$_SESSION['tmpval']['max_rows']</code>
62586256
<code>$_SESSION['tmpval']['pos']</code>
6259-
<code>$_SESSION['tmpval']['pos']</code>
6260-
<code>$_SESSION['tmpval']['pos']</code>
62616257
<code>$_SESSION['tmpval']['repeat_cells']</code>
62626258
<code>$displayParams['rowdata'][$i][$rowNumber]</code>
62636259
<code>$displaySize[0]</code>
@@ -6275,10 +6271,9 @@
62756271
<code>$statementInfo-&gt;statement-&gt;from[0]-&gt;table</code>
62766272
<code>$statementInfo-&gt;statement-&gt;limit-&gt;offset</code>
62776273
</MixedPropertyFetch>
6278-
<MixedReturnTypeCoercion occurrences="6">
6274+
<MixedReturnTypeCoercion occurrences="4">
62796275
<code>$map</code>
62806276
<code>array&lt;string, string[]&gt;</code>
6281-
<code>int[]</code>
62826277
<code>string[]</code>
62836278
</MixedReturnTypeCoercion>
62846279
<PossiblyInvalidArgument occurrences="2">

0 commit comments

Comments
 (0)