Skip to content

fix: specify parameter names in Model @phpstan-method callable types - #10444

Open
gr8man wants to merge 1 commit into
codeigniter4:developfrom
gr8man:fix/10443-model-phpstan-method-callable
Open

fix: specify parameter names in Model @phpstan-method callable types#10444
gr8man wants to merge 1 commit into
codeigniter4:developfrom
gr8man:fix/10443-model-phpstan-method-callable

Conversation

@gr8man

@gr8man gr8man commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes PhpStorm docblock parsing errors (Expected: variable) on Model @phpstan-method annotations for when() and whenNot() methods by:

  1. Adding explicit mixed type hint to $condition parameter (mixed $condition).
  2. Specifying parameter names $builder and $value in the callable(...) signature.
  3. Replacing (callable(...))|null with standard nullable type syntax ?callable(...).

Fixes #10443

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@gr8man
gr8man force-pushed the fix/10443-model-phpstan-method-callable branch from 1fe8286 to eca8178 Compare August 11, 2026 23:35

@paulbalandan paulbalandan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still red on PHPStorm.

@paulbalandan

Copy link
Copy Markdown
Member

And pls use the PR template moving forward.

@gr8man
gr8man force-pushed the fix/10443-model-phpstan-method-callable branch 2 times, most recently from 0c3f1a2 to a5fd490 Compare August 12, 2026 11:16
@paulbalandan

Copy link
Copy Markdown
Member

The issue is that PhpStorm cannot parse the parenthesis in callable:
image

Please use this fix instead:

diff --git a/system/Model.php b/system/Model.php
index ccade9cfb7..c6390298ab 100644
--- a/system/Model.php
+++ b/system/Model.php
@@ -40,6 +40,10 @@ use stdClass;
  *
  * @property-read BaseConnection $db
  *
+ * @phpstan-type WhenCallback callable(BaseBuilder, mixed): mixed
+ * @phpstan-type WhenDefaultCallback callable(BaseBuilder): mixed
+ * @phpstan-import-type row_array from BaseModel
+ *
  * @method $this groupBy($by, ?bool $escape = null)
  * @method $this groupEnd()
  * @method $this groupStart()
@@ -78,15 +82,11 @@ use stdClass;
  * @method $this selectMax(string $select = '', string $alias = '')
  * @method $this selectMin(string $select = '', string $alias = '')
  * @method $this selectSum(string $select = '', string $alias = '')
- * @method $this when($condition, callable $callback, ?callable $defaultCallback = null)
- * @method $this whenNot($condition, callable $callback, ?callable $defaultCallback = null)
+ * @method $this when($condition, WhenCallback $callback, ?WhenDefaultCallback $defaultCallback = null)
+ * @method $this whenNot($condition, WhenCallback $callback, ?WhenDefaultCallback $defaultCallback = null)
  * @method $this where($key, $value = null, ?bool $escape = null)
  * @method $this whereIn(?string $key = null, $values = null, ?bool $escape = null)
  * @method $this whereNotIn(?string $key = null, $values = null, ?bool $escape = null)
- *
- * @phpstan-method $this when($condition, callable(BaseBuilder, mixed): mixed $callback, (callable(BaseBuilder): mixed)|null $defaultCallback = null)
- * @phpstan-method $this whenNot($condition, callable(BaseBuilder, mixed): mixed $callback, (callable(BaseBuilder): mixed)|null $defaultCallback = null)
- * @phpstan-import-type row_array from BaseModel
  */
 class Model extends BaseModel
 {

@gr8man
gr8man force-pushed the fix/10443-model-phpstan-method-callable branch from a5fd490 to 5a557f7 Compare August 13, 2026 19:09
@gr8man
gr8man force-pushed the fix/10443-model-phpstan-method-callable branch from 5a557f7 to abe99a8 Compare August 13, 2026 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: PhpStorm is throwing errors on the system/ model.php when I view the code

2 participants