mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-19 17:42:23 +00:00
Updated Rector to commit 67250ca5556cb9550ac927ef9e48a1f3d4b9f598
67250ca555
[TypeDeclaration] Utilize ClassMethodReturnTypeOverrideGuard on AddReturnTypeDeclarationFromYieldsRector (#5156)
This commit is contained in:
parent
f25beaaf93
commit
950a5ddaf3
|
@ -17,9 +17,10 @@ use PhpParser\Node\Stmt\ClassMethod;
|
||||||
use PhpParser\Node\Stmt\Expression;
|
use PhpParser\Node\Stmt\Expression;
|
||||||
use PhpParser\Node\Stmt\Function_;
|
use PhpParser\Node\Stmt\Function_;
|
||||||
use PhpParser\NodeTraverser;
|
use PhpParser\NodeTraverser;
|
||||||
|
use PHPStan\Analyser\Scope;
|
||||||
use PHPStan\Type\MixedType;
|
use PHPStan\Type\MixedType;
|
||||||
use PHPStan\Type\Type;
|
use PHPStan\Type\Type;
|
||||||
use Rector\Core\Rector\AbstractRector;
|
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||||
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
|
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
|
||||||
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
|
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
|
||||||
|
@ -27,13 +28,14 @@ use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||||
use Rector\StaticTypeMapper\StaticTypeMapper;
|
use Rector\StaticTypeMapper\StaticTypeMapper;
|
||||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedGenericObjectType;
|
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedGenericObjectType;
|
||||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||||
|
use Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard;
|
||||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||||
/**
|
/**
|
||||||
* @see \Rector\Tests\TypeDeclaration\Rector\FunctionLike\AddReturnTypeDeclarationFromYieldsRector\AddReturnTypeDeclarationFromYieldsRectorTest
|
* @see \Rector\Tests\TypeDeclaration\Rector\FunctionLike\AddReturnTypeDeclarationFromYieldsRector\AddReturnTypeDeclarationFromYieldsRectorTest
|
||||||
*/
|
*/
|
||||||
final class AddReturnTypeDeclarationFromYieldsRector extends AbstractRector implements MinPhpVersionInterface
|
final class AddReturnTypeDeclarationFromYieldsRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @readonly
|
* @readonly
|
||||||
|
@ -50,11 +52,17 @@ final class AddReturnTypeDeclarationFromYieldsRector extends AbstractRector impl
|
||||||
* @var \Rector\StaticTypeMapper\StaticTypeMapper
|
* @var \Rector\StaticTypeMapper\StaticTypeMapper
|
||||||
*/
|
*/
|
||||||
private $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->typeFactory = $typeFactory;
|
||||||
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
|
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
|
||||||
$this->staticTypeMapper = $staticTypeMapper;
|
$this->staticTypeMapper = $staticTypeMapper;
|
||||||
|
$this->classMethodReturnTypeOverrideGuard = $classMethodReturnTypeOverrideGuard;
|
||||||
}
|
}
|
||||||
public function getRuleDefinition() : RuleDefinition
|
public function getRuleDefinition() : RuleDefinition
|
||||||
{
|
{
|
||||||
|
@ -91,7 +99,7 @@ CODE_SAMPLE
|
||||||
/**
|
/**
|
||||||
* @param Function_|ClassMethod|Closure $node
|
* @param Function_|ClassMethod|Closure $node
|
||||||
*/
|
*/
|
||||||
public function refactor(Node $node) : ?Node
|
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||||
{
|
{
|
||||||
$yieldNodes = $this->findCurrentScopeYieldNodes($node);
|
$yieldNodes = $this->findCurrentScopeYieldNodes($node);
|
||||||
if ($yieldNodes === []) {
|
if ($yieldNodes === []) {
|
||||||
|
@ -101,6 +109,9 @@ CODE_SAMPLE
|
||||||
if ($node->returnType instanceof Node && $this->isNames($node->returnType, ['Iterator', 'Generator', 'Traversable'])) {
|
if ($node->returnType instanceof Node && $this->isNames($node->returnType, ['Iterator', 'Generator', 'Traversable'])) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
$yieldType = $this->resolveYieldType($yieldNodes, $node);
|
$yieldType = $this->resolveYieldType($yieldNodes, $node);
|
||||||
$returnTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($yieldType, TypeKind::RETURN);
|
$returnTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($yieldType, TypeKind::RETURN);
|
||||||
if (!$returnTypeNode instanceof Node) {
|
if (!$returnTypeNode instanceof Node) {
|
||||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const PACKAGE_VERSION = '668da1d020b596441b274ee6bf9d1ed763f8e43d';
|
public const PACKAGE_VERSION = '67250ca5556cb9550ac927ef9e48a1f3d4b9f598';
|
||||||
/**
|
/**
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const RELEASE_DATE = '2023-10-11 22:47:09';
|
public const RELEASE_DATE = '2023-10-11 23:01:08';
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user