Tip about adding @phpstan-impure where applicable#5031
Tip about adding @phpstan-impure where applicable#5031ondrejmirtes wants to merge 4 commits into2.1.xfrom
@phpstan-impure where applicable#5031Conversation
ondrejmirtes
left a comment
There was a problem hiding this comment.
@phpstan-bot fix them please
src/Analyser/NodeScopeResolver.php
Outdated
| ) { | ||
| $scope = $scope->assignExpression( | ||
| new PossiblyImpureCallExpr($normalizedExpr, $normalizedExpr, sprintf('%s()', $functionReflection->getName()), $parametersAcceptor->getReturnType()), | ||
| new MixedType(), |
There was a problem hiding this comment.
Instead of the fourth PossiblyImpureCallExpr constructor parameter, this type could be carried as the expression type instead of new MixedType().
| ->tip('Remove remaining cases below this one and this error will disappear too.') | ||
| ->build(); | ||
| ->identifier('match.alwaysTrue'); | ||
| if (!$errorBuilder->hasTips()) { |
There was a problem hiding this comment.
It's a new error builder, it's not going to have any tips on this line.
| return $ruleErrorBuilder; | ||
| } | ||
| if ($ruleErrorBuilder->hasTips()) { | ||
| return $ruleErrorBuilder; |
There was a problem hiding this comment.
We don't need this condition, it's okay to have more than one tip. I suspect we could remove the hasTips method declaration altogether.
|
Claude finished @ondrejmirtes's task in 3m 33s —— View job Addressed review comments
Changes made
Commit: |
- Carry declared return type as expression type in assignExpression() instead of as a PossiblyImpureCallExpr constructor parameter - Remove unnecessary hasTips() check on new error builder in MatchExpressionRule - Remove hasTips condition in PossiblyImpureTipHelper and remove hasTips() method from RuleErrorBuilder Co-authored-by: Ondřej Mirtes <ondrejmirtes@users.noreply.github.com>
ondrejmirtes
left a comment
There was a problem hiding this comment.
@phpstan-bot re-run make cs, make tests and make phpstan and fix the failures
|
Claude finished @ondrejmirtes's task in 15m 49s —— View job Fixed CS, tests, and PHPStan failures
Changes made
Note: The integration test failures (shipmonk/phpstan-rules, PMMP, laravel) are unrelated to these fixes — shipmonk's failure is an expected behavioral change from the match expression rule changes, while PMMP/laravel failures are about |
- Add missing `use function assert;` import in MutatingScope.php - Add @template generic type annotations to PossiblyImpureTipHelper::addTip() - Update ElseIfConstantConditionRuleTest::testBug6947 expected tip to include possibly-impure tip alongside treatPhpDocTypesAsCertain tip - Fix native-types-81.php: closures with `: string` return type now correctly resolve to native type `string` instead of `non-empty-string` (the previous `non-empty-string` was due to a closure type cache key collision between regular and native-promoted scopes) Co-authored-by: Ondřej Mirtes <ondrejmirtes@users.noreply.github.com>
src/Analyser/NodeScopeResolver.php
Outdated
| && $this->rememberPossiblyImpureFunctionValues | ||
| && $functionReflection->hasSideEffects()->maybe() | ||
| && !$functionReflection->isBuiltin() | ||
| && $parametersAcceptor !== null |
There was a problem hiding this comment.
this condition should be checked before $functionReflection->hasSideEffects()->maybe()
| && $parametersAcceptor !== null | ||
| && $scope->isInClass() |
There was a problem hiding this comment.
these 2 lines should be moved above $methodReflection->hasSideEffects()->maybe()
|
@phpstan-bot ^^ fix what @staabm says Also instead of changing the expectations in native-types-81.php, could you fix the closure cache key collision? |
|
Claude finished @ondrejmirtes's task in 10m 3s —— View job Addressed @staabm's review comments and fixed closure cache key collision
Changes made
|
- Move $parametersAcceptor !== null check before hasSideEffects()->maybe() for function calls - Move $scope->isInClass() and getClassReflection()->is() checks before hasSideEffects()->maybe() for static method calls - Fix closure type cache key collision between PHPDoc-aware and native scopes by including nativeTypesPromoted flag in getClosureScopeCacheKey() - Revert native-types-81.php test expectations back to original values Co-authored-by: Ondřej Mirtes <ondrejmirtes@users.noreply.github.com>
| $parts[] = sprintf(',%s', $parameter->getType()->describe(VerbosityLevel::cache())); | ||
| } | ||
|
|
||
| if ($this->nativeTypesPromoted) { |
There was a problem hiding this comment.
I don't think this fix is right. I think instead it should go over $this->nativeExpressionTypes same way it currently does over $this->expressionTypes.
Closes phpstan/phpstan#14183