Skip to content

Commit

Permalink
[DeadCode] Remove direct return STOP_TRAVERSAL on RemoveDeadInstanceO…
Browse files Browse the repository at this point in the history
…fRector (#4188)

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user authored Jun 12, 2023
1 parent 9141715 commit a9efd72
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
5 changes: 5 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Rector\CodingStyle\Rector\String_\UseClassKeywordForClassNameResolutionRector;
use Rector\CodingStyle\ValueObject\ReturnArrayClassMethodToYield;
use Rector\Config\RectorConfig;
use Rector\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector;
use Rector\Naming\Rector\Class_\RenamePropertyToMatchTypeRector;
use Rector\Naming\Rector\ClassMethod\RenameParamToMatchTypeRector;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
Expand Down Expand Up @@ -76,6 +77,10 @@
__DIR__ . '/src/PhpParser/NodeTraverser/RectorNodeTraverser.php',
],

RenameVariableToMatchMethodCallReturnTypeRector::class => [
__DIR__ . '/packages/Config/RectorConfig.php',
],

StringClassNameToClassConstantRector::class,
__DIR__ . '/bin/validate-phpstan-version.php',
// tests
Expand Down
15 changes: 3 additions & 12 deletions rules/DeadCode/Rector/If_/RemoveDeadInstanceOfRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Do_;
use PhpParser\Node\Stmt\For_;
use PhpParser\Node\Stmt\Foreach_;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\While_;
use PhpParser\NodeTraverser;
use PHPStan\Type\MixedType;
use Rector\Core\NodeManipulator\IfManipulator;
Expand Down Expand Up @@ -65,20 +61,15 @@ function run(stdClass $stdClass)
*/
public function getNodeTypes(): array
{
return [If_::class, For_::class, Foreach_::class, While_::class, Do_::class];
return [If_::class];
}

/**
* @param If_|For_|Foreach_|While_|Do_ $node
* @param If_ $node
* @return Stmt[]|null|int
*/
public function refactor(Node $node)
public function refactor(Node $node): array|null|int
{
// avoid ifs in a loop, as unexpected behavior
if (! $node instanceof If_) {
return NodeTraverser::STOP_TRAVERSAL;
}

if (! $this->ifManipulator->isIfWithoutElseAndElseIfs($node)) {
return null;
}
Expand Down
6 changes: 5 additions & 1 deletion src/PhpParser/NodeFinder/PropertyFetchFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ private function isInAnonymous(PropertyFetch $propertyFetch, Class_|Trait_ $clas
return false;
}

return $classReflection->getName() !== $this->nodeNameResolver->getName($class) && ! $hasTrait;
if ($classReflection->getName() === $this->nodeNameResolver->getName($class)) {
return false;
}

return ! $hasTrait;
}

private function isNamePropertyNameEquals(
Expand Down

0 comments on commit a9efd72

Please sign in to comment.