From dc4a486368531dafec29de9cc0336a0aa7af13f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Szutkowski?= Date: Sat, 29 Jun 2024 23:52:21 +0200 Subject: [PATCH 1/4] Fix for AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector --- .../OneToMany/no_collection_methods.php.inc | 39 ++++++++++ .../with_other_non_collection_methods.php.inc | 76 +++++++++++++++++++ ...nPropertyGetterByToManyAttributeRector.php | 4 +- 3 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/no_collection_methods.php.inc create mode 100644 rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/with_other_non_collection_methods.php.inc diff --git a/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/no_collection_methods.php.inc b/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/no_collection_methods.php.inc new file mode 100644 index 00000000..0c1e6c1f --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/no_collection_methods.php.inc @@ -0,0 +1,39 @@ +id; + } +} + +?> +----- +id; + } +} + +?> diff --git a/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/with_other_non_collection_methods.php.inc b/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/with_other_non_collection_methods.php.inc new file mode 100644 index 00000000..24bf6d27 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/with_other_non_collection_methods.php.inc @@ -0,0 +1,76 @@ +$name = $value; + } + + public function __get($name) + { + return $this->$name; + } + + public function __isset($name) + { + return isset($this->$name); + } + + public function getTrainings(): Collection + { + return $this->trainings; + } +} + +?> +----- +$name = $value; + } + + public function __get($name) + { + return $this->$name; + } + + public function __isset($name) + { + return isset($this->$name); + } + + /** + * @return \Doctrine\Common\Collections\Collection + */ + public function getTrainings(): Collection + { + return $this->trainings; + } +} + +?> diff --git a/rules/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector.php b/rules/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector.php index bccb2696..522ea676 100644 --- a/rules/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector.php +++ b/rules/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector.php @@ -98,7 +98,7 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node foreach ($node->getMethods() as $classMethod) { if ($this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($classMethod, $scope)) { - return null; + continue; } $property = $this->methodUniqueReturnedPropertyResolver->resolve($node, $classMethod); @@ -110,7 +110,7 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node $collectionObjectType = $this->getCollectionObjectTypeFromToManyAttribute($property); if (! $collectionObjectType instanceof FullyQualifiedObjectType) { - return null; + continue; } $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod); From 09e59f59d740604392bf4d66f5f14ff5a90f2359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Szutkowski?= Date: Sat, 29 Jun 2024 23:57:14 +0200 Subject: [PATCH 2/4] more tests --- .../association_to_not_existing_class.php.inc | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/association_to_not_existing_class.php.inc diff --git a/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/association_to_not_existing_class.php.inc b/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/association_to_not_existing_class.php.inc new file mode 100644 index 00000000..5ddefd07 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/association_to_not_existing_class.php.inc @@ -0,0 +1,43 @@ +trainings; + } +} + +?> +----- +trainings; + } +} + +?> From f693b43b79c20837b4f802e22bbd90b56deb9239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Szutkowski?= Date: Sun, 30 Jun 2024 00:00:50 +0200 Subject: [PATCH 3/4] more tests --- .../Fixture/OneToMany/association_to_not_existing_class.php.inc | 2 -- 1 file changed, 2 deletions(-) diff --git a/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/association_to_not_existing_class.php.inc b/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/association_to_not_existing_class.php.inc index 5ddefd07..b7bb1b0f 100644 --- a/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/association_to_not_existing_class.php.inc +++ b/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/association_to_not_existing_class.php.inc @@ -4,7 +4,6 @@ namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCol use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; -use Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Source\Training; #[ORM\Entity] final class Trainer @@ -26,7 +25,6 @@ namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCol use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; -use Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Source\Training; #[ORM\Entity] final class Trainer From a737693f61e46890b8f4f414cc26deb462e362fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaros=C5=82aw=20Szutkowski?= Date: Mon, 1 Jul 2024 22:35:42 +0200 Subject: [PATCH 4/4] renamed fixture file --- ...ng_class.php.inc => association_with_no_target_entity.php.inc} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/{association_to_not_existing_class.php.inc => association_with_no_target_entity.php.inc} (100%) diff --git a/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/association_to_not_existing_class.php.inc b/rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/association_with_no_target_entity.php.inc similarity index 100% rename from rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/association_to_not_existing_class.php.inc rename to rules-tests/CodeQuality/Rector/Class_/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/association_with_no_target_entity.php.inc