mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-03 18:00:50 +00:00
[TypeDeclaration] Fix param type change in class method (#577)
This commit is contained in:
parent
b3480900f3
commit
d936944aed
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector\Fixture;
|
||||
|
||||
use Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector\Source\GoOneWayInterface;
|
||||
use Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector\Source\SomeTypedService;
|
||||
|
||||
final class SkipParentGuardedMethod implements GoOneWayInterface
|
||||
{
|
||||
public function __construct(
|
||||
private SomeTypedService $someTypedService
|
||||
) {
|
||||
}
|
||||
|
||||
public function go($value)
|
||||
{
|
||||
$this->someTypedService->run($value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector\Source;
|
||||
|
||||
interface GoOneWayInterface
|
||||
{
|
||||
public function go($value);
|
||||
}
|
|
@ -72,6 +72,11 @@ final class ParentClassMethodTypeOverrideGuard
|
|||
return ! str_contains($fileName, '/vendor/');
|
||||
}
|
||||
|
||||
public function hasParentClassMethod(ClassMethod $classMethod): bool
|
||||
{
|
||||
return $this->getParentClassMethod($classMethod) instanceof MethodReflection;
|
||||
}
|
||||
|
||||
private function getParentClassMethod(ClassMethod $classMethod): ?MethodReflection
|
||||
{
|
||||
$scope = $classMethod->getAttribute(AttributeKey::SCOPE);
|
||||
|
|
|
@ -19,6 +19,7 @@ use PhpParser\Node\UnionType;
|
|||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Defluent\ConflictGuard\ParentClassMethodTypeOverrideGuard;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\TypeDeclaration\NodeAnalyzer\CallerParamMatcher;
|
||||
use Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser;
|
||||
|
@ -32,7 +33,8 @@ final class ParamTypeByMethodCallTypeRector extends AbstractRector
|
|||
{
|
||||
public function __construct(
|
||||
private CallerParamMatcher $callerParamMatcher,
|
||||
private SimpleCallableNodeTraverser $simpleCallableNodeTraverser
|
||||
private SimpleCallableNodeTraverser $simpleCallableNodeTraverser,
|
||||
private ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -142,6 +144,10 @@ CODE_SAMPLE
|
|||
return true;
|
||||
}
|
||||
|
||||
if ($this->parentClassMethodTypeOverrideGuard->hasParentClassMethod($classMethod)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$scope = $classMethod->getAttribute(AttributeKey::SCOPE);
|
||||
if (! $scope instanceof Scope) {
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue
Block a user