Skip to content

fix(phpstan): drop the null check that the trait alias lookup can not fail - #247

Merged
lisachenko merged 1 commit into
4.xfrom
fix/phpstan-redundant-null-check
Nov 2, 2026
Merged

lisachenko merged 1 commit into
4.xfrom
fix/phpstan-redundant-null-check

Conversation

@lisachenko

Copy link
Copy Markdown
Member

Summary

PHPStan fails on 4.x. The last run on its head, 1f096af, is red, and so are #245 and #246, which don't touch this code:

Traits/ReflectionClassLikeTrait.php:1303
Strict comparison using === between (int|string) and null will always evaluate to false.  (identical.alwaysFalse)

In the trait alias loop, $declaringTraitName is assigned in the same branch as $originalMethodNode, so once $originalMethodNode !== null it can't be null. PHPStan 2.3 tracks that correlation and reports the second half of $originalMethodNode === null || $declaringTraitName === null as dead. The check is reduced to $originalMethodNode === null, so behaviour is unchanged. master has the same line, and the cascade merge carries the fix there.

Testing

  • vendor/bin/phpstan analyse src (PHPStan 2.3.4): no errors (1 error before).
  • vendor/bin/phpunit: OK (13747 tests; the 133 skipped and 2 incomplete are already on 4.x).

Generated by Claude Code

… fail

The declaring trait is set together with the original method node, so PHPStan
2.3 reports the second null check as always false and fails the build of 4.x.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FxhC1DaSZY1jAz2XfyjhPa
@lisachenko
lisachenko marked this pull request as ready for review November 2, 2026 17:23
@lisachenko
lisachenko merged commit 6b12376 into 4.x Nov 2, 2026
7 checks passed
@lisachenko
lisachenko deleted the fix/phpstan-redundant-null-check branch November 2, 2026 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants