Skip to content

Commit

Permalink
refactor: fix phpstan signature for Closure (#9304)
Browse files Browse the repository at this point in the history
  • Loading branch information
neznaika0 authored Dec 10, 2024
1 parent 124a7e6 commit dae379f
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 137 deletions.
114 changes: 0 additions & 114 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
'count' => 1,
'path' => __DIR__ . '/system/BaseModel.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\BaseModel\\:\\:chunk\\(\\) has parameter \\$userFunc with no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/BaseModel.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\BaseModel\\:\\:cleanValidationRules\\(\\) has parameter \\$rules with no value type specified in iterable type array\\.$#',
Expand Down Expand Up @@ -1441,24 +1435,12 @@
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:_whereIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:_whereIn\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:addUnionStatement\\(\\) has parameter \\$union with no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:batchObjectToArray\\(\\) has parameter \\$object with no value type specified in iterable type array\\.$#',
Expand All @@ -1471,12 +1453,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:buildSubquery\\(\\) has parameter \\$builder with no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:delete\\(\\) has parameter \\$where with no value type specified in iterable type array\\.$#',
Expand Down Expand Up @@ -1561,12 +1537,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:havingIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:havingIn\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#',
Expand All @@ -1579,12 +1549,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:havingNotIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:havingNotIn\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#',
Expand Down Expand Up @@ -1645,12 +1609,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:orHavingIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:orHavingIn\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#',
Expand All @@ -1663,12 +1621,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:orHavingNotIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:orHavingNotIn\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#',
Expand Down Expand Up @@ -1699,24 +1651,12 @@
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:orWhereIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:orWhereIn\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:orWhereNotIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:orWhereNotIn\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#',
Expand Down Expand Up @@ -1783,18 +1723,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:union\\(\\) has parameter \\$union with no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:unionAll\\(\\) has parameter \\$union with no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:update\\(\\) has parameter \\$set with no value type specified in iterable type array\\.$#',
Expand Down Expand Up @@ -1849,24 +1777,12 @@
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:whereIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:whereIn\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:whereNotIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:whereNotIn\\(\\) has parameter \\$values with no value type specified in iterable type array\\.$#',
Expand Down Expand Up @@ -2047,12 +1963,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseConnection.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:prepare\\(\\) has parameter \\$func with no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Database/BaseConnection.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:prepare\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#',
Expand Down Expand Up @@ -7837,12 +7747,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Model.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Model\\:\\:chunk\\(\\) has parameter \\$userFunc with no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Model.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Model\\:\\:doDelete\\(\\) has parameter \\$id with no value type specified in iterable type array\\.$#',
Expand Down Expand Up @@ -8197,12 +8101,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Router/RouteCollection.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Router\\\\RouteCollection\\:\\:environment\\(\\) has parameter \\$callback with no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Router/RouteCollection.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Router\\\\RouteCollection\\:\\:fillRouteParams\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#',
Expand Down Expand Up @@ -10219,12 +10117,6 @@
'count' => 1,
'path' => __DIR__ . '/system/Validation/Validation.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Validation\\\\Validation\\:\\:isClosure\\(\\) has parameter \\$rule with no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Validation/Validation.php',
];
$ignoreErrors[] = [
// identifier: missingType.iterableValue
'message' => '#^Method CodeIgniter\\\\Validation\\\\Validation\\:\\:isStringList\\(\\) has parameter \\$array with no value type specified in iterable type array\\.$#',
Expand Down Expand Up @@ -17317,12 +17209,6 @@
'count' => 1,
'path' => __DIR__ . '/tests/system/Test/FilterTestTraitTest.php',
];
$ignoreErrors[] = [
// identifier: missingType.callable
'message' => '#^Method CodeIgniter\\\\Test\\\\FilterTestTraitTest\\:\\:getFilterCaller\\(\\) return type has no signature specified for Closure\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/system/Test/FilterTestTraitTest.php',
];
$ignoreErrors[] = [
// identifier: if.condNotBoolean
'message' => '#^Only booleans are allowed in an if condition, array\\<int, string\\> given\\.$#',
Expand Down
4 changes: 2 additions & 2 deletions system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,8 @@ abstract public function countAllResults(bool $reset = true, bool $test = false)
* Loops over records in batches, allowing you to operate on them.
* This method works only with dbCalls.
*
* @param int $size Size
* @param Closure $userFunc Callback Function
* @param int $size Size
* @param Closure(array<string, string>|object): mixed $userFunc Callback Function
*
* @return void
*
Expand Down
32 changes: 16 additions & 16 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ protected function whereHaving(string $qbKey, $key, $value = null, string $type
* Generates a WHERE field IN('item', 'item') SQL query,
* joined with 'AND' if appropriate.
*
* @param array|BaseBuilder|Closure|string $values The values searched on, or anonymous function with subquery
* @param array|BaseBuilder|(Closure(BaseBuilder): BaseBuilder)|null $values The values searched on, or anonymous function with subquery
*
* @return $this
*/
Expand All @@ -849,7 +849,7 @@ public function whereIn(?string $key = null, $values = null, ?bool $escape = nul
* Generates a WHERE field IN('item', 'item') SQL query,
* joined with 'OR' if appropriate.
*
* @param array|BaseBuilder|Closure|string $values The values searched on, or anonymous function with subquery
* @param array|BaseBuilder|(Closure(BaseBuilder): BaseBuilder)|null $values The values searched on, or anonymous function with subquery
*
* @return $this
*/
Expand All @@ -862,7 +862,7 @@ public function orWhereIn(?string $key = null, $values = null, ?bool $escape = n
* Generates a WHERE field NOT IN('item', 'item') SQL query,
* joined with 'AND' if appropriate.
*
* @param array|BaseBuilder|Closure|string $values The values searched on, or anonymous function with subquery
* @param array|BaseBuilder|(Closure(BaseBuilder): BaseBuilder)|null $values The values searched on, or anonymous function with subquery
*
* @return $this
*/
Expand All @@ -875,7 +875,7 @@ public function whereNotIn(?string $key = null, $values = null, ?bool $escape =
* Generates a WHERE field NOT IN('item', 'item') SQL query,
* joined with 'OR' if appropriate.
*
* @param array|BaseBuilder|Closure|string $values The values searched on, or anonymous function with subquery
* @param array|BaseBuilder|(Closure(BaseBuilder): BaseBuilder)|null $values The values searched on, or anonymous function with subquery
*
* @return $this
*/
Expand All @@ -888,7 +888,7 @@ public function orWhereNotIn(?string $key = null, $values = null, ?bool $escape
* Generates a HAVING field IN('item', 'item') SQL query,
* joined with 'AND' if appropriate.
*
* @param array|BaseBuilder|Closure|string $values The values searched on, or anonymous function with subquery
* @param array|BaseBuilder|(Closure(BaseBuilder): BaseBuilder)|null $values The values searched on, or anonymous function with subquery
*
* @return $this
*/
Expand All @@ -901,7 +901,7 @@ public function havingIn(?string $key = null, $values = null, ?bool $escape = nu
* Generates a HAVING field IN('item', 'item') SQL query,
* joined with 'OR' if appropriate.
*
* @param array|BaseBuilder|Closure|string $values The values searched on, or anonymous function with subquery
* @param array|BaseBuilder|(Closure(BaseBuilder): BaseBuilder)|null $values The values searched on, or anonymous function with subquery
*
* @return $this
*/
Expand All @@ -914,7 +914,7 @@ public function orHavingIn(?string $key = null, $values = null, ?bool $escape =
* Generates a HAVING field NOT IN('item', 'item') SQL query,
* joined with 'AND' if appropriate.
*
* @param array|BaseBuilder|Closure|string $values The values searched on, or anonymous function with subquery
* @param array|BaseBuilder|(Closure(BaseBuilder):BaseBuilder)|null $values The values searched on, or anonymous function with subquery
*
* @return $this
*/
Expand All @@ -927,7 +927,7 @@ public function havingNotIn(?string $key = null, $values = null, ?bool $escape =
* Generates a HAVING field NOT IN('item', 'item') SQL query,
* joined with 'OR' if appropriate.
*
* @param array|BaseBuilder|Closure|string $values The values searched on, or anonymous function with subquery
* @param array|BaseBuilder|(Closure(BaseBuilder): BaseBuilder)|null $values The values searched on, or anonymous function with subquery
*
* @return $this
*/
Expand All @@ -942,8 +942,8 @@ public function orHavingNotIn(?string $key = null, $values = null, ?bool $escape
* @used-by whereNotIn()
* @used-by orWhereNotIn()
*
* @param non-empty-string|null $key
* @param array|BaseBuilder|Closure|null $values The values searched on, or anonymous function with subquery
* @param non-empty-string|null $key
* @param array|BaseBuilder|(Closure(BaseBuilder): BaseBuilder)|null $values The values searched on, or anonymous function with subquery
*
* @return $this
*
Expand Down Expand Up @@ -1197,7 +1197,7 @@ protected function _like_statement(?string $prefix, string $column, ?string $not
/**
* Add UNION statement
*
* @param BaseBuilder|Closure $union
* @param BaseBuilder|Closure(BaseBuilder): BaseBuilder $union
*
* @return $this
*/
Expand All @@ -1209,7 +1209,7 @@ public function union($union)
/**
* Add UNION ALL statement
*
* @param BaseBuilder|Closure $union
* @param BaseBuilder|Closure(BaseBuilder): BaseBuilder $union
*
* @return $this
*/
Expand All @@ -1222,7 +1222,7 @@ public function unionAll($union)
* @used-by union()
* @used-by unionAll()
*
* @param BaseBuilder|Closure $union
* @param BaseBuilder|Closure(BaseBuilder): BaseBuilder $union
*
* @return $this
*/
Expand Down Expand Up @@ -3558,9 +3558,9 @@ protected function isSubquery($value): bool
}

/**
* @param BaseBuilder|Closure $builder
* @param bool $wrapped Wrap the subquery in brackets
* @param string $alias Subquery alias
* @param BaseBuilder|Closure(BaseBuilder): BaseBuilder $builder
* @param bool $wrapped Wrap the subquery in brackets
* @param string $alias Subquery alias
*/
protected function buildSubquery($builder, bool $wrapped = false, string $alias = ''): string
{
Expand Down
2 changes: 2 additions & 0 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,8 @@ public function newQuery(): BaseBuilder
* ->get();
* })
*
* @param Closure(BaseConnection): mixed $func
*
* @return BasePreparedQuery|null
*/
public function prepare(Closure $func, array $options = [])
Expand Down
4 changes: 0 additions & 4 deletions system/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,6 @@ public function getIdValue($row)
* Works with $this->builder to get the Compiled select to
* determine the rows to operate on.
* This method works only with dbCalls.
*
* @return void
*
* @throws DataException
*/
public function chunk(int $size, Closure $userFunc)
{
Expand Down
2 changes: 2 additions & 0 deletions system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,8 @@ public function view(string $from, string $view, ?array $options = null): RouteC

/**
* Limits the routes to a specified ENVIRONMENT or they won't run.
*
* @param Closure(RouteCollection): void $callback
*/
public function environment(string $env, Closure $callback): RouteCollectionInterface
{
Expand Down
Loading

0 comments on commit dae379f

Please sign in to comment.