Skip to content

Commit

Permalink
Updated Rector to commit fb3c33aec495946d0bd1b9422b9b65f44665defd
Browse files Browse the repository at this point in the history
carlos-granados/rector-src@f7ea3db [PHP8.3] add new rectors for get_class()/get_parent_class() without arguments (rectorphp#6405)
carlos-granados/rector-src@1afc647 Rectify (rectorphp#6408)
carlos-granados/rector-src@afe7c46 [DeadCode] Skip nullable @ template on RemoveUselessReturnTagRector (rectorphp#6409)
carlos-granados/rector-src@293eb97 [Php81] Skip Doctrine Embeddable on ReadOnlyPropertyRector (rectorphp#6411)
carlos-granados/rector-src@1b1807b [Privatization] Skip with parameter on PrivatizeLocalGetterToPropertyRector (rectorphp#6412)
carlos-granados/rector-src@2c67908 Fix ClassDependencyManipulator to add dependency on right position (rectorphp#6413)
carlos-granados/rector-src@29e8932 [automated] Apply Coding Standard (rectorphp#6414)
carlos-granados/rector-src@3949fc2 Move instanceof PHPStan Type to ->is*() take 1 (rectorphp#6416)
carlos-granados/rector-src@0cac71a [CodeQuality] Add fixture test for skip nullable array from property with default value (rectorphp#6417)
carlos-granados/rector-src@d2db35e [Php80] Returns null on no change on ClassPropertyAssignToConstructorPromotionRector (rectorphp#6418)
carlos-granados/rector-src@06adce3 use ->isInteger()->yes() on ReturnTypeFromStrictNewArrayRector (rectorphp#6419)
carlos-granados/rector-src@bcfb598 Add ClassNameFromObjectTypeResolver to cover TypeWithClassName instance checks (rectorphp#6420)
carlos-granados/rector-src@84bb596 [StaticTypeMapper] Reduce instanceof TypeWithClassName usage via ClassNameFromObjectTypeResolver (rectorphp#6421)
carlos-granados/rector-src@26b8b54 [Naming] Reduce instanceof ObjectType on ExpectedNameResolver (take 5) (rectorphp#6423)
carlos-granados/rector-src@5baf487 Require-dev phpstan/phpstan-deprecation-rules to show list of deprecated (rectorphp#6415)
carlos-granados/rector-src@c23ba82 [deprecation] Remove deprecated PublicConstantVisibilityRector, cleanup deprecated SetListInterface (rectorphp#6424)
carlos-granados/rector-src@c2053c7 [deprecation] Deprecate AbstractScopeAwareRector in favor of single AbstractRector (rectorphp#6425)
carlos-granados/rector-src@2c5cd97 [deprecated] Remove deprecated AbstractTestCase (rectorphp#6426)
carlos-granados/rector-src@fb3c33a Merge commit '2c5cd97a3a98ab5af9efb846f6f78738e4a195a6'
  • Loading branch information
carlos-granados committed Nov 13, 2024
1 parent f413615 commit 1556d66
Show file tree
Hide file tree
Showing 173 changed files with 862 additions and 1,500 deletions.
3 changes: 2 additions & 1 deletion config/set/php83.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Rector\Php83\Rector\ClassConst\AddTypeToConstRector;
use Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector;
use Rector\Php83\Rector\FuncCall\CombineHostPortLdapUriRector;
use Rector\Php83\Rector\FuncCall\RemoveGetClassGetParentClassNoArgsRector;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->rules([AddOverrideAttributeToOverriddenMethodsRector::class, AddTypeToConstRector::class, CombineHostPortLdapUriRector::class]);
$rectorConfig->rules([AddOverrideAttributeToOverriddenMethodsRector::class, AddTypeToConstRector::class, CombineHostPortLdapUriRector::class, RemoveGetClassGetParentClassNoArgsRector::class]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\ObjectType;
use PHPStan\Type\TypeWithClassName;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Rector\AbstractRector;
use Rector\StaticTypeMapper\Resolver\ClassNameFromObjectTypeResolver;
use Rector\ValueObject\MethodName;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand Down Expand Up @@ -163,7 +163,8 @@ private function resolveExceptionArgumentPosition(Name $exceptionName) : ?int
$parametersAcceptorWithPhpDocs = ParametersAcceptorSelector::combineAcceptors($extendedMethodReflection->getVariants());
foreach ($parametersAcceptorWithPhpDocs->getParameters() as $position => $parameterReflectionWithPhpDoc) {
$parameterType = $parameterReflectionWithPhpDoc->getType();
if (!$parameterType instanceof TypeWithClassName) {
$className = ClassNameFromObjectTypeResolver::resolve($parameterReflectionWithPhpDoc->getType());
if ($className === null) {
continue;
}
$objectType = new ObjectType('Throwable');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use PhpParser\NodeTraverser;
use PHPStan\Type\NullType;
use PHPStan\Type\UnionType;
use PHPStan\Type\VoidType;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
Expand Down Expand Up @@ -156,7 +155,7 @@ private function transformDocUnionVoidToUnionNull($node) : void
$newTypes = [];
$hasChanged = \false;
foreach ($returnType->getTypes() as $type) {
if ($type instanceof VoidType) {
if ($type->isVoid()->yes()) {
$type = new NullType();
$hasChanged = \true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
use Rector\NodeTypeResolver\PHPStan\ParametersAcceptorSelectorVariantsWrapper;
use Rector\Php80\NodeResolver\ArgumentSorter;
use Rector\Php80\NodeResolver\RequireOptionalParamResolver;
use Rector\Rector\AbstractScopeAwareRector;
use Rector\PHPStan\ScopeFetcher;
use Rector\Rector\AbstractRector;
use Rector\Reflection\ReflectionResolver;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector\OptionalParametersAfterRequiredRectorTest
*/
final class OptionalParametersAfterRequiredRector extends AbstractScopeAwareRector
final class OptionalParametersAfterRequiredRector extends AbstractRector
{
/**
* @readonly
Expand Down Expand Up @@ -89,8 +90,9 @@ public function getNodeTypes() : array
* @param ClassMethod|Function_|New_|MethodCall|StaticCall|FuncCall $node
* @return \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|null|\PhpParser\Node\Expr\New_|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\FuncCall
*/
public function refactorWithScope(Node $node, Scope $scope)
public function refactor(Node $node)
{
$scope = ScopeFetcher::fetch($node);
if ($node instanceof ClassMethod || $node instanceof Function_) {
return $this->refactorClassMethodOrFunction($node, $scope);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@
use PhpParser\Node\Stmt\Property;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\ArrayType;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use Rector\NodeAnalyzer\ExprAnalyzer;
use Rector\Php\ReservedKeywordAnalyzer;
use Rector\PhpParser\AstResolver;
use Rector\Rector\AbstractScopeAwareRector;
use Rector\PHPStan\ScopeFetcher;
use Rector\Rector\AbstractRector;
use Rector\Reflection\ReflectionResolver;
use Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer\AllAssignNodePropertyTypeInferer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector\SimplifyEmptyCheckOnEmptyArrayRectorTest
*/
final class SimplifyEmptyCheckOnEmptyArrayRector extends AbstractScopeAwareRector
final class SimplifyEmptyCheckOnEmptyArrayRector extends AbstractRector
{
/**
* @readonly
Expand Down Expand Up @@ -91,8 +92,9 @@ public function getNodeTypes() : array
/**
* @param Empty_|BooleanNot $node $node
*/
public function refactorWithScope(Node $node, Scope $scope) : ?Node
public function refactor(Node $node) : ?Node
{
$scope = ScopeFetcher::fetch($node);
if ($node instanceof BooleanNot) {
if ($node->expr instanceof Empty_ && $this->isAllowedExpr($node->expr->expr, $scope)) {
return new NotIdentical($node->expr->expr, new Array_());
Expand All @@ -113,7 +115,7 @@ private function isAllowedVariable(Variable $variable) : bool
}
private function isAllowedExpr(Expr $expr, Scope $scope) : bool
{
if (!$scope->getType($expr) instanceof ArrayType) {
if (!$scope->getType($expr)->isArray()->yes()) {
return \false;
}
if ($expr instanceof Variable) {
Expand All @@ -136,7 +138,7 @@ private function isAllowedExpr(Expr $expr, Scope $scope) : bool
$phpPropertyReflection = $classReflection->getNativeProperty($propertyName);
$nativeType = $phpPropertyReflection->getNativeType();
if (!$nativeType instanceof MixedType) {
return $nativeType instanceof ArrayType;
return $nativeType->isArray()->yes();
}
$property = $this->astResolver->resolvePropertyFromPropertyReflection($phpPropertyReflection);
/**
Expand All @@ -149,6 +151,9 @@ private function isAllowedExpr(Expr $expr, Scope $scope) : bool
return \false;
}
$type = $this->allAssignNodePropertyTypeInferer->inferProperty($property, $classReflection, $this->file);
return $type instanceof ArrayType;
if (!$type instanceof Type) {
return \false;
}
return $type->isArray()->yes();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\If_;
use PHPStan\Analyser\Scope;
use Rector\NodeAnalyzer\ExprAnalyzer;
use Rector\Rector\AbstractScopeAwareRector;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\CodeQuality\Rector\Expression\TernaryFalseExpressionToIfRector\TernaryFalseExpressionToIfRectorTest
*/
final class TernaryFalseExpressionToIfRector extends AbstractScopeAwareRector
final class TernaryFalseExpressionToIfRector extends AbstractRector
{
/**
* @readonly
Expand Down Expand Up @@ -62,7 +61,7 @@ public function getNodeTypes() : array
/**
* @param Expression $node
*/
public function refactorWithScope(Node $node, Scope $scope) : ?Node
public function refactor(Node $node) : ?Node
{
if (!$node->expr instanceof Ternary) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\For_;
use PHPStan\Analyser\Scope;
use Rector\Rector\AbstractScopeAwareRector;
use Rector\PHPStan\ScopeFetcher;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\CodeQuality\Rector\For_\ForRepeatedCountToOwnVariableRector\ForRepeatedCountToOwnVariableRectorTest
*/
final class ForRepeatedCountToOwnVariableRector extends AbstractScopeAwareRector
final class ForRepeatedCountToOwnVariableRector extends AbstractRector
{
/**
* @var string
Expand Down Expand Up @@ -64,8 +64,9 @@ public function getNodeTypes() : array
* @param For_ $node
* @return Stmt[]|null
*/
public function refactorWithScope(Node $node, Scope $scope) : ?array
public function refactor(Node $node) : ?array
{
$scope = ScopeFetcher::fetch($node);
if ($scope->hasVariableType(self::COUNTER_NAME)->yes()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
use PHPStan\Type\Generic\GenericClassStringType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\TypeWithClassName;
use Rector\Rector\AbstractRector;
use Rector\StaticTypeMapper\Resolver\ClassNameFromObjectTypeResolver;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
Expand Down Expand Up @@ -88,10 +88,7 @@ private function resolveClassName(Expr $expr) : ?string
if ($type instanceof GenericClassStringType) {
$type = $type->getGenericType();
}
if (!$type instanceof TypeWithClassName) {
return null;
}
return $type->getClassName();
return ClassNameFromObjectTypeResolver::resolve($type);
}
private function isFirstObjectType(Expr $expr) : bool
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\UnionType;
Expand Down Expand Up @@ -200,10 +199,10 @@ private function processSimplifyNullableReturn(UnionType $unionType, array $type
if (\count($types) > 2) {
return null;
}
if ($types[0] instanceof FullyQualifiedObjectType && $types[1] instanceof NullType && $className === $types[0]->getClassName()) {
if ($types[0] instanceof FullyQualifiedObjectType && $types[1]->isNull()->yes() && $className === $types[0]->getClassName()) {
return $this->createDirectReturn($expression, $expr, $unionType);
}
if ($types[0] instanceof NullType && $types[1] instanceof FullyQualifiedObjectType && $className === $types[1]->getClassName()) {
if ($types[0]->isNull()->yes() && $types[1] instanceof FullyQualifiedObjectType && $className === $types[1]->getClassName()) {
return $this->createDirectReturn($expression, $expr, $unionType);
}
if ($this->isNotTypedNullable($types, $className)) {
Expand All @@ -219,7 +218,7 @@ private function isNotTypedNullable(array $types, string $className) : bool
if (!$types[0] instanceof ObjectType) {
return \true;
}
if (!$types[1] instanceof NullType) {
if (!$types[1]->isNull()->yes()) {
return \true;
}
return $className !== $types[0]->getClassName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\MixedType;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeWithClassName;
use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\Rector\AbstractRector;
use Rector\Reflection\ReflectionResolver;
use Rector\StaticTypeMapper\Resolver\ClassNameFromObjectTypeResolver;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
Expand Down Expand Up @@ -176,15 +176,16 @@ private function createIdenticalToNull(PropertyFetch $propertyFetch) : Identical
private function matchPropertyTypeClassReflection(PropertyFetch $propertyFetch) : ?ClassReflection
{
$propertyFetchVarType = $this->getType($propertyFetch->var);
if (!$propertyFetchVarType instanceof TypeWithClassName) {
$className = ClassNameFromObjectTypeResolver::resolve($propertyFetchVarType);
if ($className === null) {
return null;
}
if ($propertyFetchVarType->getClassName() === 'stdClass') {
if ($className === 'stdClass') {
return null;
}
if (!$this->reflectionProvider->hasClass($propertyFetchVarType->getClassName())) {
if (!$this->reflectionProvider->hasClass($className)) {
return null;
}
return $this->reflectionProvider->getClass($propertyFetchVarType->getClassName());
return $this->reflectionProvider->getClass($className);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\String_;
use PHPStan\Type\TypeWithClassName;
use Rector\NodeTypeResolver\NodeTypeResolver;
use Rector\StaticTypeMapper\Resolver\ClassNameFromObjectTypeResolver;
final class ArrayCallableToMethodCallFactory
{
/**
Expand Down Expand Up @@ -42,7 +42,8 @@ public function create(Array_ $array) : ?MethodCall
return null;
}
$firstItemType = $this->nodeTypeResolver->getType($firstItem->value);
if (!$firstItemType instanceof TypeWithClassName) {
$className = ClassNameFromObjectTypeResolver::resolve($firstItemType);
if ($className === null) {
return null;
}
$string = $secondItem->value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
use PhpParser\Node\Name;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\VariadicPlaceholder;
use PHPStan\Analyser\Scope;
use Rector\Rector\AbstractScopeAwareRector;
use Rector\Rector\AbstractRector;
use Rector\ValueObject\PhpVersion;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use ReflectionException;
Expand All @@ -21,7 +20,7 @@
/**
* @see \Rector\Tests\CodingStyle\Rector\FuncCall\FunctionFirstClassCallableRector\FunctionFirstClassCallableRectorTest
*/
final class FunctionFirstClassCallableRector extends AbstractScopeAwareRector implements MinPhpVersionInterface
final class FunctionFirstClassCallableRector extends AbstractRector implements MinPhpVersionInterface
{
public function getRuleDefinition() : RuleDefinition
{
Expand Down Expand Up @@ -53,7 +52,7 @@ public function getNodeTypes() : array
{
return [FuncCall::class];
}
public function refactorWithScope(Node $node, Scope $scope) : ?FuncCall
public function refactor(Node $node) : ?FuncCall
{
if (!$node instanceof FuncCall) {
return null;
Expand Down
7 changes: 4 additions & 3 deletions rules/DeadCode/NodeAnalyzer/CallCollectionAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PHPStan\Type\MixedType;
use PHPStan\Type\TypeWithClassName;
use Rector\Enum\ObjectReference;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\NodeTypeResolver;
use Rector\StaticTypeMapper\Resolver\ClassNameFromObjectTypeResolver;
final class CallCollectionAnalyzer
{
/**
Expand All @@ -39,7 +39,8 @@ public function isExists(array $calls, string $classMethodName, string $classNam
foreach ($calls as $call) {
$callerRoot = $call instanceof StaticCall ? $call->class : $call->var;
$callerType = $this->nodeTypeResolver->getType($callerRoot);
if (!$callerType instanceof TypeWithClassName) {
$callerTypeClasName = ClassNameFromObjectTypeResolver::resolve($callerType);
if ($callerTypeClasName === null) {
// handle fluent by $this->bar()->baz()->qux()
// that methods don't have return type
if ($callerType instanceof MixedType && !$callerType->isExplicitMixed()) {
Expand All @@ -66,7 +67,7 @@ public function isExists(array $calls, string $classMethodName, string $classNam
if ($this->isSelfStatic($call) && $this->shouldSkip($call, $classMethodName)) {
return \true;
}
if ($callerType->getClassName() !== $className) {
if ($callerTypeClasName !== $className) {
continue;
}
if ($this->shouldSkip($call, $classMethodName)) {
Expand Down
Loading

0 comments on commit 1556d66

Please sign in to comment.