Skip to content

[2.x] fix(phpstan): recognize conditional model casts - #4920

Merged
imorland merged 2 commits into
flarum:2.xfrom
drewmt:fix/conditional-model-cast-analysis
Aug 12, 2026
Merged

imorland merged 2 commits into
flarum:2.xfrom
drewmt:fix/conditional-model-cast-analysis

Conversation

@drewmt

@drewmt drewmt commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Changes

  • inspect the callable arrays returned by all Conditional extender methods
  • support both arrow functions and closure return bodies without executing them
  • add end-to-end PHPStan fixtures for extension, setting, and generic conditions

Why

Conditional moved from direct extender arrays to callable|string, but the
PHPStan resolver still looked only for a direct array on
whenExtensionEnabled(). Valid model casts nested in the current callable API
were therefore reported as undefined properties.

Fixes #4808

Testing

  • Failing-first fixture reproduced property.notFound on unchanged 2.x
  • Full vendor/bin/phpstan analyse -c phpstan.neon --no-progress --error-format=table --memory-limit=2G
  • PHP syntax checks for the resolver and both fixtures
  • composer validate --no-check-publish (valid; existing dependency-constraint warnings only)

@drewmt
drewmt requested a review from a team as a code owner August 11, 2026 21:04
@imorland imorland changed the title fix(phpstan): recognize conditional model casts [2.x] fix(phpstan): recognize conditional model casts Aug 12, 2026

@imorland imorland 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 very much appreciated, thank you @drewmt

@imorland imorland added this to the 2.0.0-rc.6 milestone Aug 12, 2026
@imorland
imorland merged commit da0e777 into flarum:2.x Aug 12, 2026
19 checks passed
@drewmt

drewmt commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Thanks a lot for the review and merge! Happy to continue with the next fix when I see the next clear gap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flarum\Extend\Model::cast not working when used inside conditional extender

2 participants