Skip to content

Commit

Permalink
[NodeManipulator] Reduce parent attribute check on PropertyManipulator (
Browse files Browse the repository at this point in the history
#4377)

* [NodeManipulator] Reduce parent attribute check on PropertyManipulator

* [ci-review] Rector Rectify

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user committed Jun 29, 2023
1 parent 29dc584 commit 543bb5f
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/NodeManipulator/PropertyManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\Trait_;
use PhpParser\Node\Stmt\Unset_;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\ObjectType;
Expand Down Expand Up @@ -184,6 +183,10 @@ private function isPropertyAssignedOnlyInConstructor(

private function isChangeableContext(PropertyFetch | StaticPropertyFetch $propertyFetch, Scope $scope): bool
{
if ($propertyFetch->getAttribute(AttributeKey::IS_UNSET_VAR) === true) {
return true;
}

$parentNode = $propertyFetch->getAttribute(AttributeKey::PARENT_NODE);
if (! $parentNode instanceof Node) {
return false;
Expand All @@ -196,10 +199,6 @@ private function isChangeableContext(PropertyFetch | StaticPropertyFetch $proper
$parentNode = $parentNode->getAttribute(AttributeKey::PARENT_NODE);
}

if (! $parentNode instanceof Node) {
return false;
}

if ($parentNode instanceof Arg) {
$readArg = $this->variableToConstantGuard->isReadArg($parentNode);
if (! $readArg) {
Expand All @@ -216,7 +215,7 @@ private function isChangeableContext(PropertyFetch | StaticPropertyFetch $proper
return ! $this->readWritePropertyAnalyzer->isRead($propertyFetch, $scope);
}

return $parentNode instanceof Unset_;
return false;
}

private function isFoundByRefParam(MethodCall | StaticCall $node, Scope $scope): bool
Expand Down

0 comments on commit 543bb5f

Please sign in to comment.