mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit ebfe96b4e08b26439c2341cd45e87a7bc5f314fb
ebfe96b4e0
Drop AttributeKey::SCOPE in ClassMethodReturnTypeOverrideGuard (#4144)
This commit is contained in:
parent
945b0d7947
commit
a48c21e135
|
@ -19,7 +19,6 @@ use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
|||
use Rector\Core\Reflection\ReflectionResolver;
|
||||
use Rector\FamilyTree\Reflection\FamilyRelationsAnalyzer;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\PHPStan\ParametersAcceptorSelectorVariantsWrapper;
|
||||
use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;
|
||||
use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard;
|
||||
|
@ -86,7 +85,7 @@ final class ClassMethodReturnTypeOverrideGuard
|
|||
$this->parentClassMethodTypeOverrideGuard = $parentClassMethodTypeOverrideGuard;
|
||||
$this->filePathHelper = $filePathHelper;
|
||||
}
|
||||
public function shouldSkipClassMethod(ClassMethod $classMethod) : bool
|
||||
public function shouldSkipClassMethod(ClassMethod $classMethod, Scope $scope) : bool
|
||||
{
|
||||
// 1. skip magic methods
|
||||
if ($classMethod->isMagic()) {
|
||||
|
@ -106,7 +105,7 @@ final class ClassMethodReturnTypeOverrideGuard
|
|||
if ($classReflection->isInterface()) {
|
||||
return \true;
|
||||
}
|
||||
if (!$this->isReturnTypeChangeAllowed($classMethod)) {
|
||||
if (!$this->isReturnTypeChangeAllowed($classMethod, $scope)) {
|
||||
return \true;
|
||||
}
|
||||
$childrenClassReflections = $this->familyRelationsAnalyzer->getChildrenOfClassReflection($classReflection);
|
||||
|
@ -121,7 +120,7 @@ final class ClassMethodReturnTypeOverrideGuard
|
|||
}
|
||||
return $this->hasClassMethodExprReturn($classMethod);
|
||||
}
|
||||
private function isReturnTypeChangeAllowed(ClassMethod $classMethod) : bool
|
||||
private function isReturnTypeChangeAllowed(ClassMethod $classMethod, Scope $scope) : bool
|
||||
{
|
||||
// make sure return type is not protected by parent contract
|
||||
$parentClassMethodReflection = $this->parentClassMethodTypeOverrideGuard->getParentClassMethod($classMethod);
|
||||
|
@ -129,10 +128,6 @@ final class ClassMethodReturnTypeOverrideGuard
|
|||
if (!$parentClassMethodReflection instanceof MethodReflection) {
|
||||
return \true;
|
||||
}
|
||||
$scope = $classMethod->getAttribute(AttributeKey::SCOPE);
|
||||
if (!$scope instanceof Scope) {
|
||||
return \false;
|
||||
}
|
||||
$parametersAcceptor = ParametersAcceptorSelectorVariantsWrapper::select($parentClassMethodReflection, $classMethod, $scope);
|
||||
if ($parametersAcceptor instanceof FunctionVariantWithPhpDocs && !$parametersAcceptor->getNativeReturnType() instanceof MixedType) {
|
||||
return \false;
|
||||
|
|
|
@ -9,7 +9,6 @@ use PhpParser\Node\Stmt\ClassMethod;
|
|||
use PhpParser\Node\Stmt\Function_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\ValueObject\PhpVersion;
|
||||
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
|
@ -91,7 +90,7 @@ CODE_SAMPLE
|
|||
if (!$returnTypeNode instanceof Node) {
|
||||
return null;
|
||||
}
|
||||
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node)) {
|
||||
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope)) {
|
||||
return null;
|
||||
}
|
||||
$node->returnType = $returnTypeNode;
|
||||
|
|
|
@ -102,9 +102,7 @@ CODE_SAMPLE
|
|||
$currentStmt = $classMethodStmts[$stmtPosition];
|
||||
/** @var Assign $assign */
|
||||
$assign = $currentStmt->expr;
|
||||
/** @var Scope $assignScope */
|
||||
$assignScope = $assign->getAttribute(AttributeKey::SCOPE);
|
||||
if ($this->hasCallLikeInAssignExpr($assign, $assignScope)) {
|
||||
if ($this->hasCallLikeInAssignExpr($assign, $scope)) {
|
||||
// clean safely
|
||||
$cleanAssignedExpr = $this->cleanCastedExpr($assign->expr);
|
||||
$node->stmts[$stmtPosition] = new Expression($cleanAssignedExpr);
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\Php81\Rector\ClassConst;
|
||||
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
|
|
|
@ -8,9 +8,7 @@ use PhpParser\Node\Stmt\Class_;
|
|||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\Privatization\NodeManipulator\VisibilityManipulator;
|
||||
use Rector\Privatization\VisibilityGuard\ClassMethodVisibilityGuard;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
|
|
|
@ -6,10 +6,11 @@ namespace Rector\TypeDeclaration\Rector\ClassMethod;
|
|||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\TypeDeclaration\Guard\PhpDocNestedAnnotationGuard;
|
||||
use Rector\TypeDeclaration\Helper\PhpDocNullableTypeHelper;
|
||||
use Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard;
|
||||
|
@ -18,7 +19,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
/**
|
||||
* @see \Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnAnnotationIncorrectNullableRector\ReturnAnnotationIncorrectNullableRectorTest
|
||||
*/
|
||||
final class ReturnAnnotationIncorrectNullableRector extends AbstractRector
|
||||
final class ReturnAnnotationIncorrectNullableRector extends AbstractScopeAwareRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -85,10 +86,10 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @param ClassMethod|Function_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
{
|
||||
$returnType = $node->getReturnType();
|
||||
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node)) {
|
||||
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope)) {
|
||||
return null;
|
||||
}
|
||||
if ($returnType === null) {
|
||||
|
|
|
@ -13,8 +13,9 @@ use PhpParser\Node\Stmt\Expression;
|
|||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PhpParser\Node\Stmt\Throw_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Type\NeverType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\NodeNestingScope\ValueObject\ControlStructure;
|
||||
use Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard;
|
||||
|
@ -26,7 +27,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
*
|
||||
* @see \Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector\ReturnNeverTypeRectorTest
|
||||
*/
|
||||
final class ReturnNeverTypeRector extends AbstractRector implements MinPhpVersionInterface
|
||||
final class ReturnNeverTypeRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -69,9 +70,9 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @param ClassMethod|Function_|Closure $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
{
|
||||
if ($this->shouldSkip($node)) {
|
||||
if ($this->shouldSkip($node, $scope)) {
|
||||
return null;
|
||||
}
|
||||
$node->returnType = new Identifier('never');
|
||||
|
@ -84,7 +85,7 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $node
|
||||
*/
|
||||
private function shouldSkip($node) : bool
|
||||
private function shouldSkip($node, Scope $scope) : bool
|
||||
{
|
||||
$hasReturn = $this->betterNodeFinder->hasInstancesOfInFunctionLikeScoped($node, Return_::class);
|
||||
if ($node instanceof ClassMethod && $node->isMagic()) {
|
||||
|
@ -102,7 +103,7 @@ CODE_SAMPLE
|
|||
if (!$hasNeverNodes && !$hasNeverFuncCall) {
|
||||
return \true;
|
||||
}
|
||||
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node)) {
|
||||
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope)) {
|
||||
return \true;
|
||||
}
|
||||
if (!$node->returnType instanceof Node) {
|
||||
|
|
|
@ -11,7 +11,8 @@ use PhpParser\Node\Identifier;
|
|||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;
|
||||
use Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard;
|
||||
|
@ -21,7 +22,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
/**
|
||||
* @see \Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnDirectArrayRector\ReturnTypeFromReturnDirectArrayRectorTest
|
||||
*/
|
||||
final class ReturnTypeFromReturnDirectArrayRector extends AbstractRector implements MinPhpVersionInterface
|
||||
final class ReturnTypeFromReturnDirectArrayRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -70,12 +71,12 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @param ClassMethod|Function_|ArrowFunction $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
{
|
||||
if ($node->returnType !== null) {
|
||||
return null;
|
||||
}
|
||||
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node)) {
|
||||
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope)) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->hasReturnArray($node)) {
|
||||
|
|
|
@ -12,6 +12,7 @@ use PhpParser\Node\Name\FullyQualified;
|
|||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use PHPStan\Type\ObjectType;
|
||||
|
@ -20,7 +21,7 @@ use PHPStan\Type\Type;
|
|||
use PHPStan\Type\UnionType;
|
||||
use Rector\Core\Enum\ObjectReference;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\Reflection\ReflectionResolver;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
|
||||
|
@ -35,7 +36,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
/**
|
||||
* @see \Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnNewRector\ReturnTypeFromReturnNewRectorTest
|
||||
*/
|
||||
final class ReturnTypeFromReturnNewRector extends AbstractRector implements MinPhpVersionInterface
|
||||
final class ReturnTypeFromReturnNewRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -108,12 +109,12 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @param ClassMethod|Function_|ArrowFunction $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
{
|
||||
if ($node->returnType !== null) {
|
||||
return null;
|
||||
}
|
||||
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node)) {
|
||||
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope)) {
|
||||
return null;
|
||||
}
|
||||
if (!$node instanceof ArrowFunction) {
|
||||
|
|
|
@ -8,7 +8,8 @@ use PhpParser\Node\Expr\Closure;
|
|||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\ValueObject\PhpVersion;
|
||||
use Rector\TypeDeclaration\NodeAnalyzer\ReturnTypeAnalyzer\StrictBoolReturnTypeAnalyzer;
|
||||
use Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard;
|
||||
|
@ -18,7 +19,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
/**
|
||||
* @see \Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictBoolReturnExprRector\ReturnTypeFromStrictBoolReturnExprRectorTest
|
||||
*/
|
||||
final class ReturnTypeFromStrictBoolReturnExprRector extends AbstractRector implements MinPhpVersionInterface
|
||||
final class ReturnTypeFromStrictBoolReturnExprRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -67,12 +68,12 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @param ClassMethod|Function_|Closure $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
{
|
||||
if ($node->returnType !== null) {
|
||||
return null;
|
||||
}
|
||||
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node)) {
|
||||
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope)) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->strictBoolReturnTypeAnalyzer->hasAlwaysStrictBoolReturn($node)) {
|
||||
|
|
|
@ -5,8 +5,9 @@ namespace Rector\TypeDeclaration\Rector\ClassMethod;
|
|||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\ValueObject\PhpVersion;
|
||||
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
use Rector\TypeDeclaration\TypeAnalyzer\StrictReturnClassConstReturnTypeAnalyzer;
|
||||
|
@ -17,7 +18,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
/**
|
||||
* @see \Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictConstantReturnRector\ReturnTypeFromStrictConstantReturnRectorTest
|
||||
*/
|
||||
final class ReturnTypeFromStrictConstantReturnRector extends AbstractRector implements MinPhpVersionInterface
|
||||
final class ReturnTypeFromStrictConstantReturnRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -70,12 +71,12 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @param ClassMethod $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
{
|
||||
if ($node->returnType instanceof Node) {
|
||||
return null;
|
||||
}
|
||||
if ($this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node)) {
|
||||
if ($this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope)) {
|
||||
return null;
|
||||
}
|
||||
$matchedType = $this->strictReturnClassConstReturnTypeAnalyzer->matchAlwaysReturnConstFetch($node);
|
||||
|
|
|
@ -7,8 +7,9 @@ use PhpParser\Node;
|
|||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Type\MixedType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\ValueObject\PhpVersion;
|
||||
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
|
||||
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
|
@ -20,7 +21,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
/**
|
||||
* @see \Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNativeCallRector\ReturnTypeFromStrictNativeCallRectorTest
|
||||
*/
|
||||
final class ReturnTypeFromStrictNativeCallRector extends AbstractRector implements MinPhpVersionInterface
|
||||
final class ReturnTypeFromStrictNativeCallRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -75,12 +76,12 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @param ClassMethod|Closure|Function_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
{
|
||||
if ($node->returnType !== null) {
|
||||
return null;
|
||||
}
|
||||
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node)) {
|
||||
if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope)) {
|
||||
return null;
|
||||
}
|
||||
$nativeCallLikes = $this->strictNativeFunctionReturnTypeAnalyzer->matchAlwaysReturnNativeCallLikes($node);
|
||||
|
|
|
@ -15,6 +15,7 @@ use PhpParser\Node\Stmt\ClassMethod;
|
|||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Type\ArrayType;
|
||||
use PHPStan\Type\Constant\ConstantArrayType;
|
||||
use PHPStan\Type\MixedType;
|
||||
|
@ -23,7 +24,7 @@ use PHPStan\Type\ObjectType;
|
|||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\VerbosityLevel;
|
||||
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\ValueObject\PhpVersion;
|
||||
use Rector\NodeTypeResolver\TypeComparator\TypeComparator;
|
||||
use Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard;
|
||||
|
@ -33,7 +34,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
/**
|
||||
* @see \Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNewArrayRector\ReturnTypeFromStrictNewArrayRectorTest
|
||||
*/
|
||||
final class ReturnTypeFromStrictNewArrayRector extends AbstractRector implements MinPhpVersionInterface
|
||||
final class ReturnTypeFromStrictNewArrayRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -92,9 +93,9 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @param ClassMethod|Function_|Closure $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
{
|
||||
if ($this->shouldSkip($node)) {
|
||||
if ($this->shouldSkip($node, $scope)) {
|
||||
return null;
|
||||
}
|
||||
// 1. is variable instantiated with array
|
||||
|
@ -145,12 +146,12 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $node
|
||||
*/
|
||||
private function shouldSkip($node) : bool
|
||||
private function shouldSkip($node, Scope $scope) : bool
|
||||
{
|
||||
if ($node->returnType !== null) {
|
||||
return \true;
|
||||
}
|
||||
return $node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node);
|
||||
return $node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope);
|
||||
}
|
||||
private function changeReturnType(Node $node, Type $exprType) : void
|
||||
{
|
||||
|
|
|
@ -16,11 +16,12 @@ use PhpParser\Node\Stmt\ClassMethod;
|
|||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PhpParser\Node\UnionType as PhpParserUnionType;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Type\NullType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\Core\Php\PhpVersionProvider;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
use Rector\TypeDeclaration\NodeAnalyzer\TypeNodeUnwrapper;
|
||||
|
@ -33,7 +34,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
/**
|
||||
* @see \Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector\ReturnTypeFromStrictTypedCallRectorTest
|
||||
*/
|
||||
final class ReturnTypeFromStrictTypedCallRector extends AbstractRector implements MinPhpVersionInterface
|
||||
final class ReturnTypeFromStrictTypedCallRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -114,9 +115,9 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @param ClassMethod|Function_|Closure|ArrowFunction $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
{
|
||||
if ($this->isSkipped($node)) {
|
||||
if ($this->isSkipped($node, $scope)) {
|
||||
return null;
|
||||
}
|
||||
if ($node instanceof ArrowFunction) {
|
||||
|
@ -196,7 +197,7 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Expr\ArrowFunction $node
|
||||
*/
|
||||
private function isSkipped($node) : bool
|
||||
private function isSkipped($node, Scope $scope) : bool
|
||||
{
|
||||
if ($node instanceof ArrowFunction) {
|
||||
return $node->returnType !== null;
|
||||
|
@ -207,7 +208,7 @@ CODE_SAMPLE
|
|||
if (!$node instanceof ClassMethod) {
|
||||
return $this->isUnionPossibleReturnsVoid($node);
|
||||
}
|
||||
if ($this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node)) {
|
||||
if ($this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope)) {
|
||||
return \true;
|
||||
}
|
||||
if (!$node->isMagic()) {
|
||||
|
|
|
@ -8,10 +8,11 @@ use PhpParser\Node\Expr;
|
|||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\Php\PhpPropertyReflection;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\Reflection\ReflectionResolver;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
|
||||
|
@ -23,7 +24,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
/**
|
||||
* @see \Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedPropertyRector\ReturnTypeFromStrictTypedPropertyRectorTest
|
||||
*/
|
||||
final class ReturnTypeFromStrictTypedPropertyRector extends AbstractRector implements MinPhpVersionInterface
|
||||
final class ReturnTypeFromStrictTypedPropertyRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -82,12 +83,12 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @param ClassMethod $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
{
|
||||
if ($node->returnType !== null) {
|
||||
return null;
|
||||
}
|
||||
if ($this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node)) {
|
||||
if ($this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope)) {
|
||||
return null;
|
||||
}
|
||||
$propertyTypes = $this->resolveReturnPropertyType($node);
|
||||
|
|
|
@ -11,10 +11,11 @@ use PhpParser\Node\Expr\Ternary;
|
|||
use PhpParser\Node\Scalar;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Type\ConstantType;
|
||||
use PHPStan\Type\GeneralizePrecision;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Rector\AbstractScopeAwareRector;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
|
||||
use Rector\TypeDeclaration\ValueObject\TernaryIfElseTypes;
|
||||
|
@ -25,7 +26,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|||
/**
|
||||
* @see \Rector\Tests\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector\ReturnTypeFromStrictTernaryRectorTest
|
||||
*/
|
||||
final class ReturnTypeFromStrictTernaryRector extends AbstractRector implements MinPhpVersionInterface
|
||||
final class ReturnTypeFromStrictTernaryRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
|
@ -68,7 +69,7 @@ CODE_SAMPLE
|
|||
/**
|
||||
* @param Class_ $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
public function refactorWithScope(Node $node, Scope $scope) : ?Node
|
||||
{
|
||||
$hasChanged = \false;
|
||||
foreach ($node->getMethods() as $classMethod) {
|
||||
|
@ -93,7 +94,7 @@ CODE_SAMPLE
|
|||
if (!$this->areTypesEqual($ifType, $elseType)) {
|
||||
continue;
|
||||
}
|
||||
if ($this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($classMethod)) {
|
||||
if ($this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($classMethod, $scope)) {
|
||||
continue;
|
||||
}
|
||||
$returnTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($ifType, TypeKind::RETURN);
|
||||
|
|
|
@ -25,7 +25,6 @@ use PHPStan\Type\IntegerType;
|
|||
use PHPStan\Type\NullType;
|
||||
use PHPStan\Type\StringType;
|
||||
use PHPStan\Type\Type;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\NodeTypeResolver\PHPStan\ParametersAcceptorSelectorVariantsWrapper;
|
||||
final class AlwaysStrictScalarExprAnalyzer
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'ea26fd7427e4c1d0a4032a9c86410ef41c32569b';
|
||||
public const PACKAGE_VERSION = 'ebfe96b4e08b26439c2341cd45e87a7bc5f314fb';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-06-09 19:02:44';
|
||||
public const RELEASE_DATE = '2023-06-10 00:26:45';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit553f1b3f920a8558f09e90a9172356ae::getLoader();
|
||||
return ComposerAutoloaderInit042f4a8a3d567ee4a62b869f269da317::getLoader();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit553f1b3f920a8558f09e90a9172356ae
|
||||
class ComposerAutoloaderInit042f4a8a3d567ee4a62b869f269da317
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInit553f1b3f920a8558f09e90a9172356ae
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit553f1b3f920a8558f09e90a9172356ae', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit042f4a8a3d567ee4a62b869f269da317', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit553f1b3f920a8558f09e90a9172356ae', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit042f4a8a3d567ee4a62b869f269da317', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit553f1b3f920a8558f09e90a9172356ae::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit042f4a8a3d567ee4a62b869f269da317::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit553f1b3f920a8558f09e90a9172356ae::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit042f4a8a3d567ee4a62b869f269da317::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit553f1b3f920a8558f09e90a9172356ae
|
||||
class ComposerStaticInit042f4a8a3d567ee4a62b869f269da317
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -3128,9 +3128,9 @@ class ComposerStaticInit553f1b3f920a8558f09e90a9172356ae
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit553f1b3f920a8558f09e90a9172356ae::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit553f1b3f920a8558f09e90a9172356ae::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit553f1b3f920a8558f09e90a9172356ae::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit042f4a8a3d567ee4a62b869f269da317::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit042f4a8a3d567ee4a62b869f269da317::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit042f4a8a3d567ee4a62b869f269da317::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue