mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 13:28:18 +01:00
Updated Rector to commit 69c22013f6d127aca89b2c18070a4e27119d94bf
69c22013f6
Rollback SimpleCallableNodeTraverser usage on ByRefReturnNodeVisitor (#6624)
This commit is contained in:
parent
b15d939f9f
commit
a2f3748e83
8
vendor/composer/installed.json
vendored
8
vendor/composer/installed.json
vendored
@ -1691,12 +1691,12 @@
|
|||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
|
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
|
||||||
"reference": "a0ab15c42b25ff24b78f65ba7ce3f92072d24009"
|
"reference": "e29ed08e7f476f8fab1d71601050d798c7f63e61"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/a0ab15c42b25ff24b78f65ba7ce3f92072d24009",
|
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/e29ed08e7f476f8fab1d71601050d798c7f63e61",
|
||||||
"reference": "a0ab15c42b25ff24b78f65ba7ce3f92072d24009",
|
"reference": "e29ed08e7f476f8fab1d71601050d798c7f63e61",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -1719,7 +1719,7 @@
|
|||||||
"tomasvotruba\/class-leak": "^2.0",
|
"tomasvotruba\/class-leak": "^2.0",
|
||||||
"tracy\/tracy": "^2.10"
|
"tracy\/tracy": "^2.10"
|
||||||
},
|
},
|
||||||
"time": "2024-12-19T09:03:52+00:00",
|
"time": "2024-12-20T15:30:33+00:00",
|
||||||
"default-branch": true,
|
"default-branch": true,
|
||||||
"type": "rector-extension",
|
"type": "rector-extension",
|
||||||
"extra": {
|
"extra": {
|
||||||
|
2
vendor/composer/installed.php
vendored
2
vendor/composer/installed.php
vendored
File diff suppressed because one or more lines are too long
@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
|
|||||||
*/
|
*/
|
||||||
final class GeneratedConfig
|
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()
|
private function __construct()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ use Rector\Doctrine\CodeQuality\Rector\Class_\MoveCurrentDateTimeDefaultInEntity
|
|||||||
use Rector\Doctrine\CodeQuality\Rector\Class_\RemoveEmptyTableAttributeRector;
|
use Rector\Doctrine\CodeQuality\Rector\Class_\RemoveEmptyTableAttributeRector;
|
||||||
use Rector\Doctrine\CodeQuality\Rector\Property\CorrectDefaultTypesOnEntityPropertyRector;
|
use Rector\Doctrine\CodeQuality\Rector\Property\CorrectDefaultTypesOnEntityPropertyRector;
|
||||||
use Rector\Doctrine\CodeQuality\Rector\Property\ImproveDoctrineCollectionDocTypeInEntityRector;
|
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\TypedPropertyFromColumnTypeRector;
|
||||||
use Rector\Doctrine\CodeQuality\Rector\Property\TypedPropertyFromToManyRelationTypeRector;
|
use Rector\Doctrine\CodeQuality\Rector\Property\TypedPropertyFromToManyRelationTypeRector;
|
||||||
use Rector\Doctrine\CodeQuality\Rector\Property\TypedPropertyFromToOneRelationTypeRector;
|
use Rector\Doctrine\CodeQuality\Rector\Property\TypedPropertyFromToOneRelationTypeRector;
|
||||||
@ -17,7 +16,6 @@ use Rector\Transform\Rector\Attribute\AttributeKeyToClassConstFetchRector;
|
|||||||
use Rector\Transform\ValueObject\AttributeKeyToClassConstFetch;
|
use Rector\Transform\ValueObject\AttributeKeyToClassConstFetch;
|
||||||
return static function (RectorConfig $rectorConfig) : void {
|
return static function (RectorConfig $rectorConfig) : void {
|
||||||
$rectorConfig->rules([
|
$rectorConfig->rules([
|
||||||
MakeEntityDateTimePropertyDateTimeInterfaceRector::class,
|
|
||||||
MoveCurrentDateTimeDefaultInEntityToConstructorRector::class,
|
MoveCurrentDateTimeDefaultInEntityToConstructorRector::class,
|
||||||
CorrectDefaultTypesOnEntityPropertyRector::class,
|
CorrectDefaultTypesOnEntityPropertyRector::class,
|
||||||
ExplicitRelationCollectionRector::class,
|
ExplicitRelationCollectionRector::class,
|
||||||
|
@ -135,7 +135,7 @@ CODE_SAMPLE
|
|||||||
}
|
}
|
||||||
// update docblock with known collection type
|
// update docblock with known collection type
|
||||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);
|
$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);
|
$this->phpDocTypeChanger->changeReturnType($classMethod, $phpDocInfo, $newVarType);
|
||||||
$hasChanged = \true;
|
$hasChanged = \true;
|
||||||
}
|
}
|
||||||
|
@ -197,14 +197,14 @@ CODE_SAMPLE
|
|||||||
if (!$collectionObjectType instanceof FullyQualifiedObjectType) {
|
if (!$collectionObjectType instanceof FullyQualifiedObjectType) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$newVarType = $this->collectionTypeFactory->createType($collectionObjectType);
|
$newVarType = $this->collectionTypeFactory->createType($collectionObjectType, $this->collectionTypeResolver->hasIndexBy($property));
|
||||||
$this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $newVarType);
|
$this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $newVarType);
|
||||||
} else {
|
} else {
|
||||||
$collectionObjectType = $this->collectionTypeResolver->resolveFromToManyProperty($property);
|
$collectionObjectType = $this->collectionTypeResolver->resolveFromToManyProperty($property);
|
||||||
if (!$collectionObjectType instanceof FullyQualifiedObjectType) {
|
if (!$collectionObjectType instanceof FullyQualifiedObjectType) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$newVarType = $this->collectionTypeFactory->createType($collectionObjectType);
|
$newVarType = $this->collectionTypeFactory->createType($collectionObjectType, $this->collectionTypeResolver->hasIndexBy($property));
|
||||||
$this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $newVarType);
|
$this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $newVarType);
|
||||||
}
|
}
|
||||||
return $property;
|
return $property;
|
||||||
@ -226,7 +226,7 @@ CODE_SAMPLE
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$fullyQualifiedObjectType = new FullyQualifiedObjectType($targetEntityClassName);
|
$fullyQualifiedObjectType = new FullyQualifiedObjectType($targetEntityClassName);
|
||||||
$genericObjectType = $this->collectionTypeFactory->createType($fullyQualifiedObjectType);
|
$genericObjectType = $this->collectionTypeFactory->createType($fullyQualifiedObjectType, $this->collectionTypeResolver->hasIndexBy($property));
|
||||||
$this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $genericObjectType);
|
$this->phpDocTypeChanger->changeVarType($property, $phpDocInfo, $genericObjectType);
|
||||||
return $property;
|
return $property;
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ use PHPStan\Type\UnionType;
|
|||||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
|
||||||
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
|
||||||
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
|
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
|
||||||
|
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
|
||||||
use Rector\Doctrine\NodeAnalyzer\DoctrineEntityDetector;
|
use Rector\Doctrine\NodeAnalyzer\DoctrineEntityDetector;
|
||||||
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockClassRenamer;
|
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockClassRenamer;
|
||||||
use Rector\NodeTypeResolver\ValueObject\OldToNewType;
|
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 related to maker bundle https://symfony.com/doc/current/bundles/SymfonyMakerBundle/index.html
|
||||||
*
|
*
|
||||||
* @see \Rector\Doctrine\Tests\CodeQuality\Rector\Property\MakeEntityDateTimePropertyDateTimeInterfaceRector\MakeEntityDateTimePropertyDateTimeInterfaceRectorTest
|
* @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
|
* @readonly
|
||||||
|
@ -15,6 +15,7 @@ use PHPStan\Type\Type;
|
|||||||
use PHPStan\Type\UnionType;
|
use PHPStan\Type\UnionType;
|
||||||
use Rector\Doctrine\CodeQuality\Enum\DoctrineClass;
|
use Rector\Doctrine\CodeQuality\Enum\DoctrineClass;
|
||||||
use Rector\Doctrine\TypeAnalyzer\CollectionTypeFactory;
|
use Rector\Doctrine\TypeAnalyzer\CollectionTypeFactory;
|
||||||
|
use Rector\Doctrine\TypeAnalyzer\CollectionTypeResolver;
|
||||||
use Rector\Doctrine\TypeAnalyzer\CollectionVarTagValueNodeResolver;
|
use Rector\Doctrine\TypeAnalyzer\CollectionVarTagValueNodeResolver;
|
||||||
use Rector\NodeManipulator\AssignManipulator;
|
use Rector\NodeManipulator\AssignManipulator;
|
||||||
use Rector\NodeNameResolver\NodeNameResolver;
|
use Rector\NodeNameResolver\NodeNameResolver;
|
||||||
@ -47,7 +48,11 @@ final class SetterCollectionResolver
|
|||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
private CollectionTypeFactory $collectionTypeFactory;
|
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->assignManipulator = $assignManipulator;
|
||||||
$this->reflectionResolver = $reflectionResolver;
|
$this->reflectionResolver = $reflectionResolver;
|
||||||
@ -55,6 +60,7 @@ final class SetterCollectionResolver
|
|||||||
$this->collectionVarTagValueNodeResolver = $collectionVarTagValueNodeResolver;
|
$this->collectionVarTagValueNodeResolver = $collectionVarTagValueNodeResolver;
|
||||||
$this->staticTypeMapper = $staticTypeMapper;
|
$this->staticTypeMapper = $staticTypeMapper;
|
||||||
$this->collectionTypeFactory = $collectionTypeFactory;
|
$this->collectionTypeFactory = $collectionTypeFactory;
|
||||||
|
$this->collectionTypeResolver = $collectionTypeResolver;
|
||||||
}
|
}
|
||||||
public function resolveAssignedGenericCollectionType(Class_ $class, ClassMethod $classMethod) : ?GenericObjectType
|
public function resolveAssignedGenericCollectionType(Class_ $class, ClassMethod $classMethod) : ?GenericObjectType
|
||||||
{
|
{
|
||||||
@ -88,7 +94,7 @@ final class SetterCollectionResolver
|
|||||||
if (\count($nonCollectionTypes) === 1) {
|
if (\count($nonCollectionTypes) === 1) {
|
||||||
$soleType = $nonCollectionTypes[0];
|
$soleType = $nonCollectionTypes[0];
|
||||||
if ($soleType instanceof ArrayType && $soleType->getItemType() instanceof ObjectType) {
|
if ($soleType instanceof ArrayType && $soleType->getItemType() instanceof ObjectType) {
|
||||||
return $this->collectionTypeFactory->createType($soleType->getItemType());
|
return $this->collectionTypeFactory->createType($soleType->getItemType(), $this->collectionTypeResolver->hasIndexBy($property));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ use Rector\Doctrine\CodeQuality\Enum\OdmMappingKey;
|
|||||||
use Rector\Doctrine\NodeAnalyzer\AttributeFinder;
|
use Rector\Doctrine\NodeAnalyzer\AttributeFinder;
|
||||||
use Rector\Doctrine\PhpDoc\ShortClassExpander;
|
use Rector\Doctrine\PhpDoc\ShortClassExpander;
|
||||||
use Rector\Doctrine\TypeAnalyzer\CollectionTypeFactory;
|
use Rector\Doctrine\TypeAnalyzer\CollectionTypeFactory;
|
||||||
|
use Rector\Doctrine\TypeAnalyzer\CollectionTypeResolver;
|
||||||
use Rector\PhpParser\Node\Value\ValueResolver;
|
use Rector\PhpParser\Node\Value\ValueResolver;
|
||||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||||
final class ToManyRelationPropertyTypeResolver
|
final class ToManyRelationPropertyTypeResolver
|
||||||
@ -42,13 +43,18 @@ final class ToManyRelationPropertyTypeResolver
|
|||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
private CollectionTypeFactory $collectionTypeFactory;
|
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->phpDocInfoFactory = $phpDocInfoFactory;
|
||||||
$this->shortClassExpander = $shortClassExpander;
|
$this->shortClassExpander = $shortClassExpander;
|
||||||
$this->attributeFinder = $attributeFinder;
|
$this->attributeFinder = $attributeFinder;
|
||||||
$this->valueResolver = $valueResolver;
|
$this->valueResolver = $valueResolver;
|
||||||
$this->collectionTypeFactory = $collectionTypeFactory;
|
$this->collectionTypeFactory = $collectionTypeFactory;
|
||||||
|
$this->collectionTypeResolver = $collectionTypeResolver;
|
||||||
}
|
}
|
||||||
public function resolve(Property $property) : ?Type
|
public function resolve(Property $property) : ?Type
|
||||||
{
|
{
|
||||||
@ -92,6 +98,6 @@ final class ToManyRelationPropertyTypeResolver
|
|||||||
}
|
}
|
||||||
$entityFullyQualifiedClass = $this->shortClassExpander->resolveFqnTargetEntity($targetEntity, $property);
|
$entityFullyQualifiedClass = $this->shortClassExpander->resolveFqnTargetEntity($targetEntity, $property);
|
||||||
$fullyQualifiedObjectType = new FullyQualifiedObjectType($entityFullyQualifiedClass);
|
$fullyQualifiedObjectType = new FullyQualifiedObjectType($entityFullyQualifiedClass);
|
||||||
return $this->collectionTypeFactory->createType($fullyQualifiedObjectType);
|
return $this->collectionTypeFactory->createType($fullyQualifiedObjectType, $this->collectionTypeResolver->hasIndexBy($property));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,9 @@ use PHPStan\Type\IntegerType;
|
|||||||
use PHPStan\Type\ObjectType;
|
use PHPStan\Type\ObjectType;
|
||||||
final class CollectionTypeFactory
|
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);
|
return new GenericObjectType('Doctrine\\Common\\Collections\\Collection', $genericTypes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,9 @@ use PhpParser\Node\Attribute;
|
|||||||
use PhpParser\Node\Expr;
|
use PhpParser\Node\Expr;
|
||||||
use PhpParser\Node\Expr\ClassConstFetch;
|
use PhpParser\Node\Expr\ClassConstFetch;
|
||||||
use PhpParser\Node\Identifier;
|
use PhpParser\Node\Identifier;
|
||||||
|
use PhpParser\Node\Param;
|
||||||
use PhpParser\Node\Stmt\Property;
|
use PhpParser\Node\Stmt\Property;
|
||||||
|
use PHPStan\PhpDocParser\Ast\NodeTraverser;
|
||||||
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
|
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
|
||||||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
||||||
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
|
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\ArrayItemNode;
|
||||||
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
|
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
|
||||||
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
|
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\CollectionMapping;
|
||||||
use Rector\Doctrine\CodeQuality\Enum\EntityMappingKey;
|
use Rector\Doctrine\CodeQuality\Enum\EntityMappingKey;
|
||||||
use Rector\Doctrine\CodeQuality\Enum\OdmMappingKey;
|
use Rector\Doctrine\CodeQuality\Enum\OdmMappingKey;
|
||||||
use Rector\Doctrine\NodeAnalyzer\AttrinationFinder;
|
use Rector\Doctrine\NodeAnalyzer\AttrinationFinder;
|
||||||
use Rector\Doctrine\NodeAnalyzer\TargetEntityResolver;
|
use Rector\Doctrine\NodeAnalyzer\TargetEntityResolver;
|
||||||
use Rector\Doctrine\PhpDoc\ShortClassExpander;
|
use Rector\Doctrine\PhpDoc\ShortClassExpander;
|
||||||
|
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
|
||||||
use Rector\StaticTypeMapper\Naming\NameScopeFactory;
|
use Rector\StaticTypeMapper\Naming\NameScopeFactory;
|
||||||
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
|
||||||
final class CollectionTypeResolver
|
final class CollectionTypeResolver
|
||||||
@ -43,16 +48,26 @@ final class CollectionTypeResolver
|
|||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
private TargetEntityResolver $targetEntityResolver;
|
private TargetEntityResolver $targetEntityResolver;
|
||||||
|
/**
|
||||||
|
* @readonly
|
||||||
|
*/
|
||||||
|
private PhpDocInfoFactory $phpDocInfoFactory;
|
||||||
|
/**
|
||||||
|
* @readonly
|
||||||
|
*/
|
||||||
|
private SimpleCallableNodeTraverser $simpleCallableNodeTraverser;
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private const TARGET_DOCUMENT = 'targetDocument';
|
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->nameScopeFactory = $nameScopeFactory;
|
||||||
$this->shortClassExpander = $shortClassExpander;
|
$this->shortClassExpander = $shortClassExpander;
|
||||||
$this->attrinationFinder = $attrinationFinder;
|
$this->attrinationFinder = $attrinationFinder;
|
||||||
$this->targetEntityResolver = $targetEntityResolver;
|
$this->targetEntityResolver = $targetEntityResolver;
|
||||||
|
$this->phpDocInfoFactory = $phpDocInfoFactory;
|
||||||
|
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
|
||||||
}
|
}
|
||||||
public function resolveFromTypeNode(TypeNode $typeNode, Node $node) : ?FullyQualifiedObjectType
|
public function resolveFromTypeNode(TypeNode $typeNode, Node $node) : ?FullyQualifiedObjectType
|
||||||
{
|
{
|
||||||
@ -71,6 +86,26 @@ final class CollectionTypeResolver
|
|||||||
}
|
}
|
||||||
return null;
|
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
|
public function resolveFromToManyProperty(Property $property) : ?FullyQualifiedObjectType
|
||||||
{
|
{
|
||||||
$doctrineAnnotationTagValueNodeOrAttribute = $this->attrinationFinder->getByMany($property, CollectionMapping::TO_MANY_CLASSES);
|
$doctrineAnnotationTagValueNodeOrAttribute = $this->attrinationFinder->getByMany($property, CollectionMapping::TO_MANY_CLASSES);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user