From fc0a97466617a93d73172df2b00c07f890a953c3 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 23 Dec 2024 07:54:39 +0700 Subject: [PATCH] add read const fetch support --- ...eger_attribute_read_constant_fetch.php.inc | 55 +++++++++++++++++++ ...ingWithIntegerIdAttributeConstantFetch.php | 19 +++++++ .../Source/ValueObject/DoctrineType.php | 11 ++++ src/TypeAnalyzer/CollectionTypeFactory.php | 8 ++- 4 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 rules-tests/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector/Fixture/OneToMany/with_index_by_integer_attribute_read_constant_fetch.php.inc create mode 100644 rules-tests/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector/Source/TrainingWithIntegerIdAttributeConstantFetch.php create mode 100644 rules-tests/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector/Source/ValueObject/DoctrineType.php diff --git a/rules-tests/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector/Fixture/OneToMany/with_index_by_integer_attribute_read_constant_fetch.php.inc b/rules-tests/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector/Fixture/OneToMany/with_index_by_integer_attribute_read_constant_fetch.php.inc new file mode 100644 index 00000000..56b2cbd8 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector/Fixture/OneToMany/with_index_by_integer_attribute_read_constant_fetch.php.inc @@ -0,0 +1,55 @@ +|TrainingWithIntegerIdAttributeConstantFetch[] + */ + #[ORM\OneToMany(targetEntity: TrainingWithIntegerIdAttributeConstantFetch::class, mappedBy: 'trainer', indexBy: 'id')] + private $trainings = []; + + /** + * @var Collection|TrainingWithIntegerIdAttributeConstantFetch[] + */ + #[ORM\OneToMany(targetEntity: TrainingWithIntegerIdAttributeConstantFetch::class, mappedBy: 'trainer', indexBy: 'id2')] + private $trainings2 = []; +} + +?> +----- + + */ + #[ORM\OneToMany(targetEntity: TrainingWithIntegerIdAttributeConstantFetch::class, mappedBy: 'trainer', indexBy: 'id')] + private $trainings = []; + + /** + * @var \Doctrine\Common\Collections\Collection + */ + #[ORM\OneToMany(targetEntity: TrainingWithIntegerIdAttributeConstantFetch::class, mappedBy: 'trainer', indexBy: 'id2')] + private $trainings2 = []; +} + +?> diff --git a/rules-tests/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector/Source/TrainingWithIntegerIdAttributeConstantFetch.php b/rules-tests/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector/Source/TrainingWithIntegerIdAttributeConstantFetch.php new file mode 100644 index 00000000..e7bb39e9 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector/Source/TrainingWithIntegerIdAttributeConstantFetch.php @@ -0,0 +1,19 @@ +attrs as $attr) { if ($attr->name->toString() === 'Doctrine\ORM\Mapping\Column') { foreach ($attr->args as $arg) { - if ($arg->name instanceof Identifier && $arg->name->name === 'type' && $arg->value instanceof String_) { - $type = $arg->value->value; + if ($arg->name instanceof Identifier && $arg->name->name === 'type') { + $type = $this->valueResolver->getValue($arg->value); return $type === 'string' ? new StringType() : new IntegerType(); } }