diff --git a/rules-tests/DeadCode/Rector/Property/RemoveUnusedPrivatePropertyRector/Fixture/fluent_call_with_concat.php.inc b/rules-tests/DeadCode/Rector/Property/RemoveUnusedPrivatePropertyRector/Fixture/fluent_call_with_concat.php.inc new file mode 100644 index 00000000000..2264eca5bf8 --- /dev/null +++ b/rules-tests/DeadCode/Rector/Property/RemoveUnusedPrivatePropertyRector/Fixture/fluent_call_with_concat.php.inc @@ -0,0 +1,36 @@ +config = new Cache(); + $this->config->storePath .= self::$directory; + } +} + +?> +----- +config = new Cache(); + $this->config->storePath .= self::$directory; + } +} + +?> diff --git a/rules/Removing/NodeManipulator/ComplexNodeRemover.php b/rules/Removing/NodeManipulator/ComplexNodeRemover.php index 280a806a786..b827f254df3 100644 --- a/rules/Removing/NodeManipulator/ComplexNodeRemover.php +++ b/rules/Removing/NodeManipulator/ComplexNodeRemover.php @@ -51,10 +51,13 @@ public function removePropertyAndUsages(Property $property, array $classMethodNa continue; } - // remove assigns $assign = $this->resolveAssign($propertyFetch); - $this->assignRemover->removeAssignNode($assign); + if (! $assign instanceof Assign) { + return; + } + // remove assigns + $this->assignRemover->removeAssignNode($assign); $this->removeConstructorDependency($assign); } @@ -95,7 +98,7 @@ private function shouldSkipPropertyForClassMethod(Expr $expr, array $classMethod /** * @param PropertyFetch|StaticPropertyFetch $expr */ - private function resolveAssign(Expr $expr): Assign + private function resolveAssign(Expr $expr): ?Assign { $assign = $expr->getAttribute(AttributeKey::PARENT_NODE); @@ -104,7 +107,7 @@ private function resolveAssign(Expr $expr): Assign } if (! $assign instanceof Assign) { - throw new ShouldNotHappenException("Can't handle this situation"); + return null; } return $assign;