Updated Rector to commit 67250ca5556cb9550ac927ef9e48a1f3d4b9f598

67250ca555 [TypeDeclaration] Utilize ClassMethodReturnTypeOverrideGuard on AddReturnTypeDeclarationFromYieldsRector (#5156)
This commit is contained in:
Tomas Votruba 2023-10-11 16:04:37 +00:00
parent f25beaaf93
commit 950a5ddaf3
2 changed files with 17 additions and 6 deletions

View File

@ -17,9 +17,10 @@ use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Function_;
use PhpParser\NodeTraverser;
use PHPStan\Analyser\Scope;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
@ -27,13 +28,14 @@ use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\StaticTypeMapper\StaticTypeMapper;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedGenericObjectType;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
use Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\TypeDeclaration\Rector\FunctionLike\AddReturnTypeDeclarationFromYieldsRector\AddReturnTypeDeclarationFromYieldsRectorTest
*/
final class AddReturnTypeDeclarationFromYieldsRector extends AbstractRector implements MinPhpVersionInterface
final class AddReturnTypeDeclarationFromYieldsRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
{
/**
* @readonly
@ -50,11 +52,17 @@ final class AddReturnTypeDeclarationFromYieldsRector extends AbstractRector impl
* @var \Rector\StaticTypeMapper\StaticTypeMapper
*/
private $staticTypeMapper;
public function __construct(TypeFactory $typeFactory, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, StaticTypeMapper $staticTypeMapper)
/**
* @readonly
* @var \Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard
*/
private $classMethodReturnTypeOverrideGuard;
public function __construct(TypeFactory $typeFactory, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, StaticTypeMapper $staticTypeMapper, ClassMethodReturnTypeOverrideGuard $classMethodReturnTypeOverrideGuard)
{
$this->typeFactory = $typeFactory;
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
$this->staticTypeMapper = $staticTypeMapper;
$this->classMethodReturnTypeOverrideGuard = $classMethodReturnTypeOverrideGuard;
}
public function getRuleDefinition() : RuleDefinition
{
@ -91,7 +99,7 @@ CODE_SAMPLE
/**
* @param Function_|ClassMethod|Closure $node
*/
public function refactor(Node $node) : ?Node
public function refactorWithScope(Node $node, Scope $scope) : ?Node
{
$yieldNodes = $this->findCurrentScopeYieldNodes($node);
if ($yieldNodes === []) {
@ -101,6 +109,9 @@ CODE_SAMPLE
if ($node->returnType instanceof Node && $this->isNames($node->returnType, ['Iterator', 'Generator', 'Traversable'])) {
return null;
}
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope)) {
return null;
}
$yieldType = $this->resolveYieldType($yieldNodes, $node);
$returnTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($yieldType, TypeKind::RETURN);
if (!$returnTypeNode instanceof Node) {

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '668da1d020b596441b274ee6bf9d1ed763f8e43d';
public const PACKAGE_VERSION = '67250ca5556cb9550ac927ef9e48a1f3d4b9f598';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-10-11 22:47:09';
public const RELEASE_DATE = '2023-10-11 23:01:08';
/**
* @var int
*/