-
-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DeadCode] Make private property removal dependent on local property …
…fetches (#311)
- Loading branch information
1 parent
46843ec
commit e3727aa
Showing
27 changed files
with
61 additions
and
712 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 0 additions & 97 deletions
97
packages/NodeCollector/NodeCollector/ParsedPropertyFetchNodeCollector.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/ReadWrite/ReadNodeAnalyzer/LocalPropertyFetchReadNodeAnalyzer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\ReadWrite\ReadNodeAnalyzer; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Expr\PropertyFetch; | ||
use PhpParser\Node\Stmt\Class_; | ||
use Rector\Core\PhpParser\NodeFinder\PropertyFetchFinder; | ||
use Rector\NodeNameResolver\NodeNameResolver; | ||
use Rector\NodeTypeResolver\Node\AttributeKey; | ||
use Rector\ReadWrite\Contract\ReadNodeAnalyzerInterface; | ||
|
||
final class LocalPropertyFetchReadNodeAnalyzer implements ReadNodeAnalyzerInterface | ||
{ | ||
public function __construct( | ||
private JustReadExprAnalyzer $justReadExprAnalyzer, | ||
private PropertyFetchFinder $propertyFetchFinder, | ||
private NodeNameResolver $nodeNameResolver | ||
) { | ||
} | ||
|
||
public function supports(Node $node): bool | ||
{ | ||
return $node instanceof PropertyFetch; | ||
} | ||
|
||
/** | ||
* @param PropertyFetch $node | ||
*/ | ||
public function isRead(Node $node): bool | ||
{ | ||
$class = $node->getAttribute(AttributeKey::CLASS_NODE); | ||
if (! $class instanceof Class_) { | ||
// assume worse to keep node protected | ||
return true; | ||
} | ||
|
||
$propertyName = $this->nodeNameResolver->getName($node->name); | ||
if ($propertyName === null) { | ||
// assume worse to keep node protected | ||
return true; | ||
} | ||
|
||
$propertyFetches = $this->propertyFetchFinder->findLocalPropertyFetchesByName($class, $propertyName); | ||
foreach ($propertyFetches as $propertyFetch) { | ||
if ($this->justReadExprAnalyzer->isReadContext($propertyFetch)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
39 changes: 0 additions & 39 deletions
39
packages/ReadWrite/ReadNodeAnalyzer/PropertyFetchReadNodeAnalyzer.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 0 additions & 31 deletions
31
...ion/Rector/Property/PrivatizeLocalPropertyToPrivatePropertyRector/Fixture/fixture.php.inc
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.