Skip to content

Commit dae379f

Browse files
authored
refactor: fix phpstan signature for Closure (#9304)
1 parent 124a7e6 commit dae379f

File tree

8 files changed

+25
-137
lines changed

8 files changed

+25
-137
lines changed

phpstan-baseline.php

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@
2525
'count' => 1,
2626
'path' => __DIR__ . '/system/BaseModel.php',
2727
];
28-
$ignoreErrors[] = [
29-
// identifier: missingType.callable
30-
'message' => '#^Method CodeIgniter\\\\BaseModel\\:\\:chunk\\(\\) has parameter \\$userFunc with no signature specified for Closure\\.$#',
31-
'count' => 1,
32-
'path' => __DIR__ . '/system/BaseModel.php',
33-
];
3428
$ignoreErrors[] = [
3529
// identifier: missingType.iterableValue
3630
'message' => '#^Method CodeIgniter\\\\BaseModel\\:\\:cleanValidationRules\\(\\) has parameter \\$rules with no value type specified in iterable type array\\.$#',
@@ -1441,24 +1435,12 @@
14411435
'count' => 1,
14421436
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
14431437
];
1444-
$ignoreErrors[] = [
1445-
// identifier: missingType.callable
1446-
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:_whereIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#',
1447-
'count' => 1,
1448-
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
1449-
];
14501438
$ignoreErrors[] = [
14511439
// identifier: missingType.iterableValue
14521440
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:_whereIn\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#',
14531441
'count' => 1,
14541442
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
14551443
];
1456-
$ignoreErrors[] = [
1457-
// identifier: missingType.callable
1458-
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:addUnionStatement\\(\\) has parameter \\$union with no signature specified for Closure\\.$#',
1459-
'count' => 1,
1460-
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
1461-
];
14621444
$ignoreErrors[] = [
14631445
// identifier: missingType.iterableValue
14641446
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:batchObjectToArray\\(\\) has parameter \\$object with no value type specified in iterable type array\\.$#',
@@ -1471,12 +1453,6 @@
14711453
'count' => 1,
14721454
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
14731455
];
1474-
$ignoreErrors[] = [
1475-
// identifier: missingType.callable
1476-
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:buildSubquery\\(\\) has parameter \\$builder with no signature specified for Closure\\.$#',
1477-
'count' => 1,
1478-
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
1479-
];
14801456
$ignoreErrors[] = [
14811457
// identifier: missingType.iterableValue
14821458
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:delete\\(\\) has parameter \\$where with no value type specified in iterable type array\\.$#',
@@ -1561,12 +1537,6 @@
15611537
'count' => 1,
15621538
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
15631539
];
1564-
$ignoreErrors[] = [
1565-
// identifier: missingType.callable
1566-
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:havingIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#',
1567-
'count' => 1,
1568-
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
1569-
];
15701540
$ignoreErrors[] = [
15711541
// identifier: missingType.iterableValue
15721542
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:havingIn\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#',
@@ -1579,12 +1549,6 @@
15791549
'count' => 1,
15801550
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
15811551
];
1582-
$ignoreErrors[] = [
1583-
// identifier: missingType.callable
1584-
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:havingNotIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#',
1585-
'count' => 1,
1586-
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
1587-
];
15881552
$ignoreErrors[] = [
15891553
// identifier: missingType.iterableValue
15901554
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:havingNotIn\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#',
@@ -1645,12 +1609,6 @@
16451609
'count' => 1,
16461610
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
16471611
];
1648-
$ignoreErrors[] = [
1649-
// identifier: missingType.callable
1650-
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:orHavingIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#',
1651-
'count' => 1,
1652-
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
1653-
];
16541612
$ignoreErrors[] = [
16551613
// identifier: missingType.iterableValue
16561614
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:orHavingIn\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#',
@@ -1663,12 +1621,6 @@
16631621
'count' => 1,
16641622
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
16651623
];
1666-
$ignoreErrors[] = [
1667-
// identifier: missingType.callable
1668-
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:orHavingNotIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#',
1669-
'count' => 1,
1670-
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
1671-
];
16721624
$ignoreErrors[] = [
16731625
// identifier: missingType.iterableValue
16741626
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:orHavingNotIn\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#',
@@ -1699,24 +1651,12 @@
16991651
'count' => 1,
17001652
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
17011653
];
1702-
$ignoreErrors[] = [
1703-
// identifier: missingType.callable
1704-
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:orWhereIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#',
1705-
'count' => 1,
1706-
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
1707-
];
17081654
$ignoreErrors[] = [
17091655
// identifier: missingType.iterableValue
17101656
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:orWhereIn\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#',
17111657
'count' => 1,
17121658
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
17131659
];
1714-
$ignoreErrors[] = [
1715-
// identifier: missingType.callable
1716-
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:orWhereNotIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#',
1717-
'count' => 1,
1718-
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
1719-
];
17201660
$ignoreErrors[] = [
17211661
// identifier: missingType.iterableValue
17221662
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:orWhereNotIn\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#',
@@ -1783,18 +1723,6 @@
17831723
'count' => 1,
17841724
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
17851725
];
1786-
$ignoreErrors[] = [
1787-
// identifier: missingType.callable
1788-
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:union\\(\\) has parameter \\$union with no signature specified for Closure\\.$#',
1789-
'count' => 1,
1790-
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
1791-
];
1792-
$ignoreErrors[] = [
1793-
// identifier: missingType.callable
1794-
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:unionAll\\(\\) has parameter \\$union with no signature specified for Closure\\.$#',
1795-
'count' => 1,
1796-
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
1797-
];
17981726
$ignoreErrors[] = [
17991727
// identifier: missingType.iterableValue
18001728
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:update\\(\\) has parameter \\$set with no value type specified in iterable type array\\.$#',
@@ -1849,24 +1777,12 @@
18491777
'count' => 1,
18501778
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
18511779
];
1852-
$ignoreErrors[] = [
1853-
// identifier: missingType.callable
1854-
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:whereIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#',
1855-
'count' => 1,
1856-
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
1857-
];
18581780
$ignoreErrors[] = [
18591781
// identifier: missingType.iterableValue
18601782
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:whereIn\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#',
18611783
'count' => 1,
18621784
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
18631785
];
1864-
$ignoreErrors[] = [
1865-
// identifier: missingType.callable
1866-
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:whereNotIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#',
1867-
'count' => 1,
1868-
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
1869-
];
18701786
$ignoreErrors[] = [
18711787
// identifier: missingType.iterableValue
18721788
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:whereNotIn\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#',
@@ -2047,12 +1963,6 @@
20471963
'count' => 1,
20481964
'path' => __DIR__ . '/system/Database/BaseConnection.php',
20491965
];
2050-
$ignoreErrors[] = [
2051-
// identifier: missingType.callable
2052-
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:prepare\\(\\) has parameter \\$func with no signature specified for Closure\\.$#',
2053-
'count' => 1,
2054-
'path' => __DIR__ . '/system/Database/BaseConnection.php',
2055-
];
20561966
$ignoreErrors[] = [
20571967
// identifier: missingType.iterableValue
20581968
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:prepare\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#',
@@ -7837,12 +7747,6 @@
78377747
'count' => 1,
78387748
'path' => __DIR__ . '/system/Model.php',
78397749
];
7840-
$ignoreErrors[] = [
7841-
// identifier: missingType.callable
7842-
'message' => '#^Method CodeIgniter\\\\Model\\:\\:chunk\\(\\) has parameter \\$userFunc with no signature specified for Closure\\.$#',
7843-
'count' => 1,
7844-
'path' => __DIR__ . '/system/Model.php',
7845-
];
78467750
$ignoreErrors[] = [
78477751
// identifier: missingType.iterableValue
78487752
'message' => '#^Method CodeIgniter\\\\Model\\:\\:doDelete\\(\\) has parameter \\$id with no value type specified in iterable type array\\.$#',
@@ -8197,12 +8101,6 @@
81978101
'count' => 1,
81988102
'path' => __DIR__ . '/system/Router/RouteCollection.php',
81998103
];
8200-
$ignoreErrors[] = [
8201-
// identifier: missingType.callable
8202-
'message' => '#^Method CodeIgniter\\\\Router\\\\RouteCollection\\:\\:environment\\(\\) has parameter \\$callback with no signature specified for Closure\\.$#',
8203-
'count' => 1,
8204-
'path' => __DIR__ . '/system/Router/RouteCollection.php',
8205-
];
82068104
$ignoreErrors[] = [
82078105
// identifier: missingType.iterableValue
82088106
'message' => '#^Method CodeIgniter\\\\Router\\\\RouteCollection\\:\\:fillRouteParams\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#',
@@ -10219,12 +10117,6 @@
1021910117
'count' => 1,
1022010118
'path' => __DIR__ . '/system/Validation/Validation.php',
1022110119
];
10222-
$ignoreErrors[] = [
10223-
// identifier: missingType.callable
10224-
'message' => '#^Method CodeIgniter\\\\Validation\\\\Validation\\:\\:isClosure\\(\\) has parameter \\$rule with no signature specified for Closure\\.$#',
10225-
'count' => 1,
10226-
'path' => __DIR__ . '/system/Validation/Validation.php',
10227-
];
1022810120
$ignoreErrors[] = [
1022910121
// identifier: missingType.iterableValue
1023010122
'message' => '#^Method CodeIgniter\\\\Validation\\\\Validation\\:\\:isStringList\\(\\) has parameter \\$array with no value type specified in iterable type array\\.$#',
@@ -17317,12 +17209,6 @@
1731717209
'count' => 1,
1731817210
'path' => __DIR__ . '/tests/system/Test/FilterTestTraitTest.php',
1731917211
];
17320-
$ignoreErrors[] = [
17321-
// identifier: missingType.callable
17322-
'message' => '#^Method CodeIgniter\\\\Test\\\\FilterTestTraitTest\\:\\:getFilterCaller\\(\\) return type has no signature specified for Closure\\.$#',
17323-
'count' => 1,
17324-
'path' => __DIR__ . '/tests/system/Test/FilterTestTraitTest.php',
17325-
];
1732617212
$ignoreErrors[] = [
1732717213
// identifier: if.condNotBoolean
1732817214
'message' => '#^Only booleans are allowed in an if condition, array\\<int, string\\> given\\.$#',

system/BaseModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,8 @@ abstract public function countAllResults(bool $reset = true, bool $test = false)
570570
* Loops over records in batches, allowing you to operate on them.
571571
* This method works only with dbCalls.
572572
*
573-
* @param int $size Size
574-
* @param Closure $userFunc Callback Function
573+
* @param int $size Size
574+
* @param Closure(array<string, string>|object): mixed $userFunc Callback Function
575575
*
576576
* @return void
577577
*

system/Database/BaseBuilder.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ protected function whereHaving(string $qbKey, $key, $value = null, string $type
836836
* Generates a WHERE field IN('item', 'item') SQL query,
837837
* joined with 'AND' if appropriate.
838838
*
839-
* @param array|BaseBuilder|Closure|string $values The values searched on, or anonymous function with subquery
839+
* @param array|BaseBuilder|(Closure(BaseBuilder): BaseBuilder)|null $values The values searched on, or anonymous function with subquery
840840
*
841841
* @return $this
842842
*/
@@ -849,7 +849,7 @@ public function whereIn(?string $key = null, $values = null, ?bool $escape = nul
849849
* Generates a WHERE field IN('item', 'item') SQL query,
850850
* joined with 'OR' if appropriate.
851851
*
852-
* @param array|BaseBuilder|Closure|string $values The values searched on, or anonymous function with subquery
852+
* @param array|BaseBuilder|(Closure(BaseBuilder): BaseBuilder)|null $values The values searched on, or anonymous function with subquery
853853
*
854854
* @return $this
855855
*/
@@ -862,7 +862,7 @@ public function orWhereIn(?string $key = null, $values = null, ?bool $escape = n
862862
* Generates a WHERE field NOT IN('item', 'item') SQL query,
863863
* joined with 'AND' if appropriate.
864864
*
865-
* @param array|BaseBuilder|Closure|string $values The values searched on, or anonymous function with subquery
865+
* @param array|BaseBuilder|(Closure(BaseBuilder): BaseBuilder)|null $values The values searched on, or anonymous function with subquery
866866
*
867867
* @return $this
868868
*/
@@ -875,7 +875,7 @@ public function whereNotIn(?string $key = null, $values = null, ?bool $escape =
875875
* Generates a WHERE field NOT IN('item', 'item') SQL query,
876876
* joined with 'OR' if appropriate.
877877
*
878-
* @param array|BaseBuilder|Closure|string $values The values searched on, or anonymous function with subquery
878+
* @param array|BaseBuilder|(Closure(BaseBuilder): BaseBuilder)|null $values The values searched on, or anonymous function with subquery
879879
*
880880
* @return $this
881881
*/
@@ -888,7 +888,7 @@ public function orWhereNotIn(?string $key = null, $values = null, ?bool $escape
888888
* Generates a HAVING field IN('item', 'item') SQL query,
889889
* joined with 'AND' if appropriate.
890890
*
891-
* @param array|BaseBuilder|Closure|string $values The values searched on, or anonymous function with subquery
891+
* @param array|BaseBuilder|(Closure(BaseBuilder): BaseBuilder)|null $values The values searched on, or anonymous function with subquery
892892
*
893893
* @return $this
894894
*/
@@ -901,7 +901,7 @@ public function havingIn(?string $key = null, $values = null, ?bool $escape = nu
901901
* Generates a HAVING field IN('item', 'item') SQL query,
902902
* joined with 'OR' if appropriate.
903903
*
904-
* @param array|BaseBuilder|Closure|string $values The values searched on, or anonymous function with subquery
904+
* @param array|BaseBuilder|(Closure(BaseBuilder): BaseBuilder)|null $values The values searched on, or anonymous function with subquery
905905
*
906906
* @return $this
907907
*/
@@ -914,7 +914,7 @@ public function orHavingIn(?string $key = null, $values = null, ?bool $escape =
914914
* Generates a HAVING field NOT IN('item', 'item') SQL query,
915915
* joined with 'AND' if appropriate.
916916
*
917-
* @param array|BaseBuilder|Closure|string $values The values searched on, or anonymous function with subquery
917+
* @param array|BaseBuilder|(Closure(BaseBuilder):BaseBuilder)|null $values The values searched on, or anonymous function with subquery
918918
*
919919
* @return $this
920920
*/
@@ -927,7 +927,7 @@ public function havingNotIn(?string $key = null, $values = null, ?bool $escape =
927927
* Generates a HAVING field NOT IN('item', 'item') SQL query,
928928
* joined with 'OR' if appropriate.
929929
*
930-
* @param array|BaseBuilder|Closure|string $values The values searched on, or anonymous function with subquery
930+
* @param array|BaseBuilder|(Closure(BaseBuilder): BaseBuilder)|null $values The values searched on, or anonymous function with subquery
931931
*
932932
* @return $this
933933
*/
@@ -942,8 +942,8 @@ public function orHavingNotIn(?string $key = null, $values = null, ?bool $escape
942942
* @used-by whereNotIn()
943943
* @used-by orWhereNotIn()
944944
*
945-
* @param non-empty-string|null $key
946-
* @param array|BaseBuilder|Closure|null $values The values searched on, or anonymous function with subquery
945+
* @param non-empty-string|null $key
946+
* @param array|BaseBuilder|(Closure(BaseBuilder): BaseBuilder)|null $values The values searched on, or anonymous function with subquery
947947
*
948948
* @return $this
949949
*
@@ -1197,7 +1197,7 @@ protected function _like_statement(?string $prefix, string $column, ?string $not
11971197
/**
11981198
* Add UNION statement
11991199
*
1200-
* @param BaseBuilder|Closure $union
1200+
* @param BaseBuilder|Closure(BaseBuilder): BaseBuilder $union
12011201
*
12021202
* @return $this
12031203
*/
@@ -1209,7 +1209,7 @@ public function union($union)
12091209
/**
12101210
* Add UNION ALL statement
12111211
*
1212-
* @param BaseBuilder|Closure $union
1212+
* @param BaseBuilder|Closure(BaseBuilder): BaseBuilder $union
12131213
*
12141214
* @return $this
12151215
*/
@@ -1222,7 +1222,7 @@ public function unionAll($union)
12221222
* @used-by union()
12231223
* @used-by unionAll()
12241224
*
1225-
* @param BaseBuilder|Closure $union
1225+
* @param BaseBuilder|Closure(BaseBuilder): BaseBuilder $union
12261226
*
12271227
* @return $this
12281228
*/
@@ -3558,9 +3558,9 @@ protected function isSubquery($value): bool
35583558
}
35593559

35603560
/**
3561-
* @param BaseBuilder|Closure $builder
3562-
* @param bool $wrapped Wrap the subquery in brackets
3563-
* @param string $alias Subquery alias
3561+
* @param BaseBuilder|Closure(BaseBuilder): BaseBuilder $builder
3562+
* @param bool $wrapped Wrap the subquery in brackets
3563+
* @param string $alias Subquery alias
35643564
*/
35653565
protected function buildSubquery($builder, bool $wrapped = false, string $alias = ''): string
35663566
{

system/Database/BaseConnection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,8 @@ public function newQuery(): BaseBuilder
959959
* ->get();
960960
* })
961961
*
962+
* @param Closure(BaseConnection): mixed $func
963+
*
962964
* @return BasePreparedQuery|null
963965
*/
964966
public function prepare(Closure $func, array $options = [])

system/Model.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,6 @@ public function getIdValue($row)
623623
* Works with $this->builder to get the Compiled select to
624624
* determine the rows to operate on.
625625
* This method works only with dbCalls.
626-
*
627-
* @return void
628-
*
629-
* @throws DataException
630626
*/
631627
public function chunk(int $size, Closure $userFunc)
632628
{

system/Router/RouteCollection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,8 @@ public function view(string $from, string $view, ?array $options = null): RouteC
11581158

11591159
/**
11601160
* Limits the routes to a specified ENVIRONMENT or they won't run.
1161+
*
1162+
* @param Closure(RouteCollection): void $callback
11611163
*/
11621164
public function environment(string $env, Closure $callback): RouteCollectionInterface
11631165
{

0 commit comments

Comments
 (0)