Skip to content

Commit

Permalink
[DeadCode] Remove AstResolver usage on RecastingRemovalRector (#5109)
Browse files Browse the repository at this point in the history
* [DeadCode] Remove AstResolver usage on RecastingRemovalRector

* add more fixture for external resource
  • Loading branch information
samsonasik committed Oct 3, 2023
1 parent 6a89b43 commit d7710f8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
@@ -0,0 +1,33 @@
<?php

namespace Rector\Tests\DeadCode\Rector\Cast\RecastingRemovalRector\Fixture;

use Rector\Tests\DeadCode\Rector\Cast\RecastingRemovalRector\Source\ExternalStrictReturnType;

class MethodCallReturnStrictTypeExternal
{
public function run(): string
{
$obj = new ExternalStrictReturnType();
return (string) $obj->getResult();
}
}

?>
-----
<?php

namespace Rector\Tests\DeadCode\Rector\Cast\RecastingRemovalRector\Fixture;

use Rector\Tests\DeadCode\Rector\Cast\RecastingRemovalRector\Source\ExternalStrictReturnType;

class MethodCallReturnStrictTypeExternal
{
public function run(): string
{
$obj = new ExternalStrictReturnType();
return $obj->getResult();
}
}

?>
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\DeadCode\Rector\Cast\RecastingRemovalRector\Source;

final class ExternalStrictReturnType
{
public function getResult(): string
{
return 'test';
}
}
13 changes: 3 additions & 10 deletions rules/DeadCode/Rector/Cast/RecastingRemovalRector.php
Expand Up @@ -16,7 +16,6 @@
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Reflection\Php\PhpPropertyReflection;
use PHPStan\Type\ArrayType;
use PHPStan\Type\BooleanType;
Expand All @@ -29,7 +28,6 @@
use PHPStan\Type\UnionType;
use Rector\Core\NodeAnalyzer\ExprAnalyzer;
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
use Rector\Core\PhpParser\AstResolver;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Reflection\ReflectionResolver;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand All @@ -55,8 +53,7 @@ final class RecastingRemovalRector extends AbstractRector
public function __construct(
private readonly PropertyFetchAnalyzer $propertyFetchAnalyzer,
private readonly ReflectionResolver $reflectionResolver,
private readonly ExprAnalyzer $exprAnalyzer,
private readonly AstResolver $astResolver
private readonly ExprAnalyzer $exprAnalyzer
) {
}

Expand Down Expand Up @@ -128,12 +125,8 @@ private function shouldSkipCall(Expr $expr): bool
return false;
}

$classMethod = $this->astResolver->resolveClassMethodFromCall($expr);
if (! $classMethod instanceof ClassMethod) {
return false;
}

return ! $classMethod->returnType instanceof Node;
$type = $this->nodeTypeResolver->getNativeType($expr);
return $type instanceof MixedType && ! $type->isExplicitMixed();
}

private function shouldSkip(Expr $expr): bool
Expand Down

0 comments on commit d7710f8

Please sign in to comment.