Introduce all-methods-are-(im)pure
Rework of https://github.com/phpstan/phpstan-src/pull/4409 and https://github.com/phpstan/phpstan-src/pull/4415
I added a non regression of https://github.com/phpstan/phpstan/issues/10215 as a proof it works.
I don't like the naming of my methods, suggestion are opened.
Also I'm not fully sure getDefaultMethodPurity shouldn't be called somewhere else too...
I dunno which strategy you will prefer @ondrejmirtes between
-
doing calls like
isPure() ?? getDefaultMethodPurity()like https://github.com/phpstan/phpstan-src/pull/4422/commits/846d7bd2d2bc0e5db775f981e958a5c2873aa11a#diff-fb5399c56567ad1b8be9256fe9008a03a43b7686e02156b9f1b3118e76d95e2fR895 -
or using the fallback directly in the
isPuremethod like https://github.com/phpstan/phpstan-src/pull/4422/files#diff-260042b10e8fde4d3e77fce0c1fc6fcf0851c7e442271dbefb5eded974d607e6R837-R843
The second one seems simpler to me because isPure was used multiple times like in NodeScopeResolver::getPhpDocs and it would have require more changes.
This pull request has been marked as ready for review.
I think it's ready for a new review :)
Lot of test added and void behavior :)
@staabm Do you see a case where
$scope->getFunctionType($node->getReturnType(), false, false)->isVoid()->maybe()
is possible or does the mutation testing reports a useless mutant ?
I did not look into all details of this PR, but maybe you can do something like
class X {
public function returnsVoid(): void{}
public function returnsInt(): int{}
public function doFoo() {
$method = rand(0,1) ? 'returnsVoid' : 'returnsInt';
$something = $this->$method();
}
}