Skip to content

Commit

Permalink
[CodeQuality] Handle crash on unary minums on OptionalParametersAfter…
Browse files Browse the repository at this point in the history
…RequiredRector
  • Loading branch information
samsonasik committed Dec 11, 2024
1 parent 13fc72a commit 115d9bc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector\Fixture;

final class SkipFirstClassCallableInUnary
{
public function getSubscribedEvents(string $nodePath)
{
return -$this->textElement(...);
}

public function textElement() { return 1; }
}
14 changes: 13 additions & 1 deletion src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\NullsafeMethodCall;
use PhpParser\Node\Expr\PostDec;
use PhpParser\Node\Expr\PostInc;
use PhpParser\Node\Expr\PreDec;
use PhpParser\Node\Expr\PreInc;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Expr\UnaryMinus;
use PhpParser\Node\Expr\UnaryPlus;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Expr\Yield_;
use PhpParser\Node\Expr\YieldFrom;
Expand Down Expand Up @@ -180,12 +186,18 @@ public function processNodes(
$node instanceof Return_ ||
$node instanceof EnumCase ||
$node instanceof Cast ||
$node instanceof YieldFrom
$node instanceof YieldFrom ||
$node instanceof UnaryMinus ||
$node instanceof UnaryPlus
) && $node->expr instanceof Expr) {
$node->expr->setAttribute(AttributeKey::SCOPE, $mutatingScope);
return;
}

if ($node instanceof PostInc || $node instanceof PostDec || $node instanceof PreInc || $node instanceof PreDec) {
$node->var->setAttribute(AttributeKey::SCOPE, $mutatingScope);
}

if ($node instanceof Assign || $node instanceof AssignOp) {
$this->processAssign($node, $mutatingScope);

Expand Down

0 comments on commit 115d9bc

Please sign in to comment.