Updated Rector to commit 69c22013f6d127aca89b2c18070a4e27119d94bf

69c22013f6 Rollback SimpleCallableNodeTraverser usage on ByRefReturnNodeVisitor (#6624)
This commit is contained in:
Tomas Votruba 2024-12-20 15:33:39 +00:00
parent b15d939f9f
commit a2f3748e83
11 changed files with 68 additions and 20 deletions

View File

@ -1691,12 +1691,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
"reference": "a0ab15c42b25ff24b78f65ba7ce3f92072d24009"
"reference": "e29ed08e7f476f8fab1d71601050d798c7f63e61"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/a0ab15c42b25ff24b78f65ba7ce3f92072d24009",
"reference": "a0ab15c42b25ff24b78f65ba7ce3f92072d24009",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/e29ed08e7f476f8fab1d71601050d798c7f63e61",
"reference": "e29ed08e7f476f8fab1d71601050d798c7f63e61",
"shasum": ""
},
"require": {
@ -1719,7 +1719,7 @@
"tomasvotruba\/class-leak": "^2.0",
"tracy\/tracy": "^2.10"
},
"time": "2024-12-19T09:03:52+00:00",
"time": "2024-12-20T15:30:33+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main a0ab15c'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 183795c'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 4bd1f6e'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 29a1abf'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main e29ed08'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 183795c'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 4bd1f6e'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 29a1abf'));
private function __construct()
{
}

View File

@ -9,7 +9,6 @@ use Rector\Doctrine\CodeQuality\Rector\Class_\MoveCurrentDateTimeDefaultInEntity
use Rector\Doctrine\CodeQuality\Rector\Class_\RemoveEmptyTableAttributeRector;
use Rector\Doctrine\CodeQuality\Rector\Property\CorrectDefaultTypesOnEntityPropertyRector;
use Rector\Doctrine\CodeQuality\Rector\Property\ImproveDoctrineCollectionDocTypeInEntityRector;
use Rector\Doctrine\CodeQuality\Rector\Property\MakeEntityDateTimePropertyDateTimeInterfaceRector;
use Rector\Doctrine\CodeQuality\Rector\Property\TypedPropertyFromColumnTypeRector;
use Rector\Doctrine\CodeQuality\Rector\Property\TypedPropertyFromToManyRelationTypeRector;
use Rector\Doctrine\CodeQuality\Rector\Property\TypedPropertyFromToOneRelationTypeRector;
@ -17,7 +16,6 @@ use Rector\Transform\Rector\Attribute\AttributeKeyToClassConstFetchRector;
use Rector\Transform\ValueObject\AttributeKeyToClassConstFetch;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->rules([
MakeEntityDateTimePropertyDateTimeInterfaceRector::class,
MoveCurrentDateTimeDefaultInEntityToConstructorRector::class,
CorrectDefaultTypesOnEntityPropertyRector::class,
ExplicitRelationCollectionRector::class,

View File

@ -135,7 +135,7 @@ CODE_SAMPLE
}
// update docblock with known collection type
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);
$newVarType = $this->collectionTypeFactory->createType($collectionObjectType);
$newVarType = $this->collectionTypeFactory->createType($collectionObjectType, $this->collectionTypeResolver->hasIndexBy($property));
$this->phpDocTypeChanger->changeReturnType($classMethod, $phpDocInfo, $newVarType);
$hasChanged = \true;
}

View File

@ -197,14 +197,14 @@ CODE_SAMPLE
if (!$collectionObjectType instanceof FullyQualifiedObjectType) {
return null;
}
$newVarType = $this->collectionTypeFactory->createType($collectionObjectType);
$newVarType = $this->collectionTypeFactory->createType($collectionObjectType, $this->collectionTypeResolver->hasIndexBy($property));
$this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $newVarType);
} else {
$collectionObjectType = $this->collectionTypeResolver->resolveFromToManyProperty($property);
if (!$collectionObjectType instanceof FullyQualifiedObjectType) {
return null;
}
$newVarType = $this->collectionTypeFactory->createType($collectionObjectType);
$newVarType = $this->collectionTypeFactory->createType($collectionObjectType, $this->collectionTypeResolver->hasIndexBy($property));
$this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $newVarType);
}
return $property;
@ -226,7 +226,7 @@ CODE_SAMPLE
return null;
}
$fullyQualifiedObjectType = new FullyQualifiedObjectType($targetEntityClassName);
$genericObjectType = $this->collectionTypeFactory->createType($fullyQualifiedObjectType);
$genericObjectType = $this->collectionTypeFactory->createType($fullyQualifiedObjectType, $this->collectionTypeResolver->hasIndexBy($property));
$this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $genericObjectType);
return $property;
}

View File

@ -12,6 +12,7 @@ use PHPStan\Type\UnionType;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
use Rector\Doctrine\NodeAnalyzer\DoctrineEntityDetector;
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockClassRenamer;
use Rector\NodeTypeResolver\ValueObject\OldToNewType;
@ -23,8 +24,10 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
* @see related to maker bundle https://symfony.com/doc/current/bundles/SymfonyMakerBundle/index.html
*
* @see \Rector\Doctrine\Tests\CodeQuality\Rector\Property\MakeEntityDateTimePropertyDateTimeInterfaceRector\MakeEntityDateTimePropertyDateTimeInterfaceRectorTest
*
* @deprecated see https://github.com/rectorphp/rector-doctrine/issues/356 for reasoning
*/
final class MakeEntityDateTimePropertyDateTimeInterfaceRector extends AbstractRector
final class MakeEntityDateTimePropertyDateTimeInterfaceRector extends AbstractRector implements DeprecatedInterface
{
/**
* @readonly

View File

@ -15,6 +15,7 @@ use PHPStan\Type\Type;
use PHPStan\Type\UnionType;
use Rector\Doctrine\CodeQuality\Enum\DoctrineClass;
use Rector\Doctrine\TypeAnalyzer\CollectionTypeFactory;
use Rector\Doctrine\TypeAnalyzer\CollectionTypeResolver;
use Rector\Doctrine\TypeAnalyzer\CollectionVarTagValueNodeResolver;
use Rector\NodeManipulator\AssignManipulator;
use Rector\NodeNameResolver\NodeNameResolver;
@ -47,7 +48,11 @@ final class SetterCollectionResolver
* @readonly
*/
private CollectionTypeFactory $collectionTypeFactory;
public function __construct(AssignManipulator $assignManipulator, ReflectionResolver $reflectionResolver, NodeNameResolver $nodeNameResolver, CollectionVarTagValueNodeResolver $collectionVarTagValueNodeResolver, StaticTypeMapper $staticTypeMapper, CollectionTypeFactory $collectionTypeFactory)
/**
* @readonly
*/
private CollectionTypeResolver $collectionTypeResolver;
public function __construct(AssignManipulator $assignManipulator, ReflectionResolver $reflectionResolver, NodeNameResolver $nodeNameResolver, CollectionVarTagValueNodeResolver $collectionVarTagValueNodeResolver, StaticTypeMapper $staticTypeMapper, CollectionTypeFactory $collectionTypeFactory, CollectionTypeResolver $collectionTypeResolver)
{
$this->assignManipulator = $assignManipulator;
$this->reflectionResolver = $reflectionResolver;
@ -55,6 +60,7 @@ final class SetterCollectionResolver
$this->collectionVarTagValueNodeResolver = $collectionVarTagValueNodeResolver;
$this->staticTypeMapper = $staticTypeMapper;
$this->collectionTypeFactory = $collectionTypeFactory;
$this->collectionTypeResolver = $collectionTypeResolver;
}
public function resolveAssignedGenericCollectionType(Class_ $class, ClassMethod $classMethod) : ?GenericObjectType
{
@ -88,7 +94,7 @@ final class SetterCollectionResolver
if (\count($nonCollectionTypes) === 1) {
$soleType = $nonCollectionTypes[0];
if ($soleType instanceof ArrayType && $soleType->getItemType() instanceof ObjectType) {
return $this->collectionTypeFactory->createType($soleType->getItemType());
return $this->collectionTypeFactory->createType($soleType->getItemType(), $this->collectionTypeResolver->hasIndexBy($property));
}
}
}

View File

@ -18,6 +18,7 @@ use Rector\Doctrine\CodeQuality\Enum\OdmMappingKey;
use Rector\Doctrine\NodeAnalyzer\AttributeFinder;
use Rector\Doctrine\PhpDoc\ShortClassExpander;
use Rector\Doctrine\TypeAnalyzer\CollectionTypeFactory;
use Rector\Doctrine\TypeAnalyzer\CollectionTypeResolver;
use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
final class ToManyRelationPropertyTypeResolver
@ -42,13 +43,18 @@ final class ToManyRelationPropertyTypeResolver
* @readonly
*/
private CollectionTypeFactory $collectionTypeFactory;
public function __construct(PhpDocInfoFactory $phpDocInfoFactory, ShortClassExpander $shortClassExpander, AttributeFinder $attributeFinder, ValueResolver $valueResolver, CollectionTypeFactory $collectionTypeFactory)
/**
* @readonly
*/
private CollectionTypeResolver $collectionTypeResolver;
public function __construct(PhpDocInfoFactory $phpDocInfoFactory, ShortClassExpander $shortClassExpander, AttributeFinder $attributeFinder, ValueResolver $valueResolver, CollectionTypeFactory $collectionTypeFactory, CollectionTypeResolver $collectionTypeResolver)
{
$this->phpDocInfoFactory = $phpDocInfoFactory;
$this->shortClassExpander = $shortClassExpander;
$this->attributeFinder = $attributeFinder;
$this->valueResolver = $valueResolver;
$this->collectionTypeFactory = $collectionTypeFactory;
$this->collectionTypeResolver = $collectionTypeResolver;
}
public function resolve(Property $property) : ?Type
{
@ -92,6 +98,6 @@ final class ToManyRelationPropertyTypeResolver
}
$entityFullyQualifiedClass = $this->shortClassExpander->resolveFqnTargetEntity($targetEntity, $property);
$fullyQualifiedObjectType = new FullyQualifiedObjectType($entityFullyQualifiedClass);
return $this->collectionTypeFactory->createType($fullyQualifiedObjectType);
return $this->collectionTypeFactory->createType($fullyQualifiedObjectType, $this->collectionTypeResolver->hasIndexBy($property));
}
}

View File

@ -8,9 +8,9 @@ use PHPStan\Type\IntegerType;
use PHPStan\Type\ObjectType;
final class CollectionTypeFactory
{
public function createType(ObjectType $objectType) : GenericObjectType
public function createType(ObjectType $objectType, bool $withIndexBy) : GenericObjectType
{
$genericTypes = [new IntegerType(), $objectType];
$genericTypes = $withIndexBy ? [$objectType] : [new IntegerType(), $objectType];
return new GenericObjectType('Doctrine\\Common\\Collections\\Collection', $genericTypes);
}
}

View File

@ -9,7 +9,9 @@ use PhpParser\Node\Attribute;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Identifier;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Property;
use PHPStan\PhpDocParser\Ast\NodeTraverser;
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
@ -17,12 +19,15 @@ use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Doctrine\CodeQuality\Enum\CollectionMapping;
use Rector\Doctrine\CodeQuality\Enum\EntityMappingKey;
use Rector\Doctrine\CodeQuality\Enum\OdmMappingKey;
use Rector\Doctrine\NodeAnalyzer\AttrinationFinder;
use Rector\Doctrine\NodeAnalyzer\TargetEntityResolver;
use Rector\Doctrine\PhpDoc\ShortClassExpander;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
use Rector\StaticTypeMapper\Naming\NameScopeFactory;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
final class CollectionTypeResolver
@ -43,16 +48,26 @@ final class CollectionTypeResolver
* @readonly
*/
private TargetEntityResolver $targetEntityResolver;
/**
* @readonly
*/
private PhpDocInfoFactory $phpDocInfoFactory;
/**
* @readonly
*/
private SimpleCallableNodeTraverser $simpleCallableNodeTraverser;
/**
* @var string
*/
private const TARGET_DOCUMENT = 'targetDocument';
public function __construct(NameScopeFactory $nameScopeFactory, ShortClassExpander $shortClassExpander, AttrinationFinder $attrinationFinder, TargetEntityResolver $targetEntityResolver)
public function __construct(NameScopeFactory $nameScopeFactory, ShortClassExpander $shortClassExpander, AttrinationFinder $attrinationFinder, TargetEntityResolver $targetEntityResolver, PhpDocInfoFactory $phpDocInfoFactory, SimpleCallableNodeTraverser $simpleCallableNodeTraverser)
{
$this->nameScopeFactory = $nameScopeFactory;
$this->shortClassExpander = $shortClassExpander;
$this->attrinationFinder = $attrinationFinder;
$this->targetEntityResolver = $targetEntityResolver;
$this->phpDocInfoFactory = $phpDocInfoFactory;
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
}
public function resolveFromTypeNode(TypeNode $typeNode, Node $node) : ?FullyQualifiedObjectType
{
@ -71,6 +86,26 @@ final class CollectionTypeResolver
}
return null;
}
/**
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
*/
public function hasIndexBy($property) : bool
{
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($property);
if ($phpDocInfo instanceof PhpDocInfo && \strpos((string) $phpDocInfo->getPhpDocNode(), 'indexBy') !== \false) {
return \true;
}
$attrGroups = $property->attrGroups;
$hasIndexBy = \false;
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($attrGroups, function (Node $node) use(&$hasIndexBy) : ?int {
if ($node instanceof Arg && $node->name instanceof Identifier && $node->name->toString() === 'indexBy') {
$hasIndexBy = \true;
return NodeTraverser::STOP_TRAVERSAL;
}
return null;
});
return $hasIndexBy;
}
public function resolveFromToManyProperty(Property $property) : ?FullyQualifiedObjectType
{
$doctrineAnnotationTagValueNodeOrAttribute = $this->attrinationFinder->getByMany($property, CollectionMapping::TO_MANY_CLASSES);