Skip to content

Commit

Permalink
[DeadCode] Handle fluent call with concat in RemoveUnusedPrivatePrope…
Browse files Browse the repository at this point in the history
…rtyRector (#73)
  • Loading branch information
samsonasik committed May 19, 2021
1 parent 1d11be6 commit 3e80d2a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Rector\Tests\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector\Fixture;

class FluentCallWithConcat
{
private static $directory = 'CacheFactory';
private $cacheFactory;
private $config;

public function run()
{
$this->config = new Cache();
$this->config->storePath .= self::$directory;
}
}

?>
-----
<?php

namespace Rector\Tests\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector\Fixture;

class FluentCallWithConcat
{
private static $directory = 'CacheFactory';
private $config;

public function run()
{
$this->config = new Cache();
$this->config->storePath .= self::$directory;
}
}

?>
11 changes: 7 additions & 4 deletions rules/Removing/NodeManipulator/ComplexNodeRemover.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);

Expand All @@ -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;
Expand Down

0 comments on commit 3e80d2a

Please sign in to comment.