Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"hoa/compiler": "3.17.08.08",
"hoa/exception": "^1.0",
"hoa/file": "1.17.07.11",
"jetbrains/phpstorm-stubs": "dev-master#bdc8acd7c04c0c87197849c7cdd27e44b67b56c7",
"jetbrains/phpstorm-stubs": "dev-master#5686f9ceebde3d9338bea53b78d70ebde5fb5710",
"nette/bootstrap": "^3.0",
"nette/di": "^3.1.4",
"nette/neon": "3.3.3",
Expand Down
18 changes: 9 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PhpParser\Node;
use PHPStan\Analyser\NullsafeOperatorHelper;
use PHPStan\Analyser\Scope;
use PHPStan\Node\NoopExpressionNode;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Rules\RuleLevelHelper;
Expand All @@ -14,7 +15,7 @@
use function sprintf;

/**
* @implements Rule<Node\Stmt\Expression>
* @implements Rule<NoopExpressionNode>
*/
final class CallToMethodStatementWithoutSideEffectsRule implements Rule
{
Expand All @@ -25,18 +26,18 @@ public function __construct(private RuleLevelHelper $ruleLevelHelper)

public function getNodeType(): string
{
return Node\Stmt\Expression::class;
return NoopExpressionNode::class;
}

public function processNode(Node $node, Scope $scope): array
{
if ($node->expr instanceof Node\Expr\NullsafeMethodCall) {
$scope = $scope->filterByTruthyValue(new Node\Expr\BinaryOp\NotIdentical($node->expr->var, new Node\Expr\ConstFetch(new Node\Name('null'))));
} elseif (!$node->expr instanceof Node\Expr\MethodCall) {
$methodCall = $node->getOriginalExpr();
if ($methodCall instanceof Node\Expr\NullsafeMethodCall) {
$scope = $scope->filterByTruthyValue(new Node\Expr\BinaryOp\NotIdentical($methodCall->var, new Node\Expr\ConstFetch(new Node\Name('null'))));
} elseif (!$methodCall instanceof Node\Expr\MethodCall) {
return [];
}

$methodCall = $node->expr;
if (!$methodCall->name instanceof Node\Identifier) {
return [];
}
Expand All @@ -61,8 +62,8 @@ public function processNode(Node $node, Scope $scope): array
}

$method = $calledOnType->getMethod($methodName, $scope);
if ($method->hasSideEffects()->no() || $node->expr->isFirstClassCallable()) {
if (!$node->expr->isFirstClassCallable()) {
if ($method->hasSideEffects()->no() || $methodCall->isFirstClassCallable()) {
if (!$methodCall->isFirstClassCallable()) {
$throwsType = $method->getThrowType();
if ($throwsType !== null && !$throwsType->isVoid()->yes()) {
return [];
Expand Down
Loading