From 6bd5c5227d5ab49770134387f70a52807c0dac7d Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 25 Jul 2024 15:39:18 +0200 Subject: [PATCH 1/3] include ODM in description --- docs/rector_rules_overview.md | 2 +- .../Rector/Class_/ExplicitRelationCollectionRector.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/rector_rules_overview.md b/docs/rector_rules_overview.md index 661868dc..d5b7a3e4 100644 --- a/docs/rector_rules_overview.md +++ b/docs/rector_rules_overview.md @@ -120,7 +120,7 @@ Replace EventSubscriberInterface with AsDoctrineListener attribute(s) ## ExplicitRelationCollectionRector -Use explicit collection in one-to-many relations of Doctrine entity +Use Collection object type for one-to-many relations of Doctrine entity/ODM document - class: [`Rector\Doctrine\CodeQuality\Rector\Class_\ExplicitRelationCollectionRector`](../rules/CodeQuality/Rector/Class_/ExplicitRelationCollectionRector.php) diff --git a/rules/CodeQuality/Rector/Class_/ExplicitRelationCollectionRector.php b/rules/CodeQuality/Rector/Class_/ExplicitRelationCollectionRector.php index 134bdc6d..5b2d04c8 100644 --- a/rules/CodeQuality/Rector/Class_/ExplicitRelationCollectionRector.php +++ b/rules/CodeQuality/Rector/Class_/ExplicitRelationCollectionRector.php @@ -37,7 +37,9 @@ public function __construct( public function getRuleDefinition(): RuleDefinition { - return new RuleDefinition('Use explicit collection in one-to-many relations of Doctrine entity', [ + return new RuleDefinition( + 'Use Collection object type for one-to-many relations of Doctrine entity/ODM document', + [ new CodeSample( <<<'CODE_SAMPLE' use Doctrine\ORM\Mapping\OneToMany; @@ -71,6 +73,7 @@ public function __construct() } CODE_SAMPLE ), + ]); } From 424855941f1120c57c9b88d1b8bb8d7bfbfc7d09 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 25 Jul 2024 16:56:12 +0200 Subject: [PATCH 2/3] misc --- config/sets/typed-collections.php | 1 + .../Class_/ExplicitRelationCollectionRector.php | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/config/sets/typed-collections.php b/config/sets/typed-collections.php index 466a446b..d5ae92b8 100644 --- a/config/sets/typed-collections.php +++ b/config/sets/typed-collections.php @@ -10,4 +10,5 @@ ->withRules([ ExplicitRelationCollectionRector::class, AddReturnDocBlockToCollectionPropertyGetterByToManyAnnotationRector::class, + \Rector\Doctrine\CodeQuality\Rector\Property\ImproveDoctrineCollectionDocTypeInEntityRector::class, ]); diff --git a/rules/CodeQuality/Rector/Class_/ExplicitRelationCollectionRector.php b/rules/CodeQuality/Rector/Class_/ExplicitRelationCollectionRector.php index 5b2d04c8..305793ad 100644 --- a/rules/CodeQuality/Rector/Class_/ExplicitRelationCollectionRector.php +++ b/rules/CodeQuality/Rector/Class_/ExplicitRelationCollectionRector.php @@ -40,8 +40,8 @@ public function getRuleDefinition(): RuleDefinition return new RuleDefinition( 'Use Collection object type for one-to-many relations of Doctrine entity/ODM document', [ - new CodeSample( - <<<'CODE_SAMPLE' + new CodeSample( + <<<'CODE_SAMPLE' use Doctrine\ORM\Mapping\OneToMany; use Doctrine\ORM\Mapping\Entity; @@ -53,8 +53,8 @@ class SomeClass } CODE_SAMPLE - , - <<<'CODE_SAMPLE' + , + <<<'CODE_SAMPLE' use Doctrine\ORM\Mapping\Entity; use Doctrine\ORM\Mapping\OneToMany; use Doctrine\Common\Collections\ArrayCollection; @@ -72,9 +72,10 @@ public function __construct() } } CODE_SAMPLE - ), - - ]); + ), + + ] + ); } /** From b2a201c63baff4abc8fae6c84145744cf189d2c7 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 25 Jul 2024 17:05:50 +0200 Subject: [PATCH 3/3] fix namespace --- config/sets/typed-collections.php | 3 +- .../Fixture/ManyToMany/adder_param.php.inc | 4 +- .../adder_param_with_typehint_only.php.inc | 4 +- .../Fixture/ManyToMany/no_var.php.inc | 4 +- .../ManyToMany/no_var_attribute.php.inc | 4 +- .../ManyToMany/param_without_array.php.inc | 4 +- .../skip_collection_generic_class.php.inc | 2 +- .../skip_collection_generic_object.php.inc | 2 +- .../Fixture/ManyToMany/var_fixture.php.inc | 4 +- .../Fixture/ManyToMany/var_static.php.inc | 4 +- .../ManyToMany/var_without_array.php.inc | 4 +- .../ManyToMany/var_without_collection.php.inc | 4 +- .../Fixture/Odm/orm_many.php.inc | 50 +++++++++++++++++++ .../Fixture/OneToMany/adder_param.php.inc | 4 +- .../adder_param_with_typehint_only.php.inc | 4 +- .../Fixture/OneToMany/no_var.php.inc | 4 +- .../OneToMany/no_var_attribute.php.inc | 4 +- .../OneToMany/param_without_array.php.inc | 4 +- .../skip_collection_generic_class.php.inc | 2 +- .../skip_collection_generic_object.php.inc | 2 +- .../Fixture/OneToMany/var_fixture.php.inc | 4 +- .../Fixture/OneToMany/var_static.php.inc | 4 +- .../OneToMany/var_without_array.php.inc | 4 +- .../OneToMany/var_without_collection.php.inc | 4 +- 24 files changed, 92 insertions(+), 41 deletions(-) create mode 100644 rules-tests/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector/Fixture/Odm/orm_many.php.inc diff --git a/config/sets/typed-collections.php b/config/sets/typed-collections.php index d5ae92b8..63663a72 100644 --- a/config/sets/typed-collections.php +++ b/config/sets/typed-collections.php @@ -5,10 +5,11 @@ use Rector\Config\RectorConfig; use Rector\Doctrine\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAnnotationRector; use Rector\Doctrine\CodeQuality\Rector\Class_\ExplicitRelationCollectionRector; +use Rector\Doctrine\CodeQuality\Rector\Property\ImproveDoctrineCollectionDocTypeInEntityRector; return RectorConfig::configure() ->withRules([ ExplicitRelationCollectionRector::class, AddReturnDocBlockToCollectionPropertyGetterByToManyAnnotationRector::class, - \Rector\Doctrine\CodeQuality\Rector\Property\ImproveDoctrineCollectionDocTypeInEntityRector::class, + ImproveDoctrineCollectionDocTypeInEntityRector::class, ]); diff --git a/rules-tests/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector/Fixture/ManyToMany/adder_param.php.inc b/rules-tests/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector/Fixture/ManyToMany/adder_param.php.inc index 66490ad5..25e6fb4f 100644 --- a/rules-tests/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector/Fixture/ManyToMany/adder_param.php.inc +++ b/rules-tests/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector/Fixture/ManyToMany/adder_param.php.inc @@ -1,6 +1,6 @@ items; + } +} + +?> +----- + + */ + private $items = []; + + public function getItems() + { + return $this->items; + } +} + +?> diff --git a/rules-tests/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector/Fixture/OneToMany/adder_param.php.inc b/rules-tests/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector/Fixture/OneToMany/adder_param.php.inc index 3c3f7080..a19e8ea3 100644 --- a/rules-tests/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector/Fixture/OneToMany/adder_param.php.inc +++ b/rules-tests/CodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector/Fixture/OneToMany/adder_param.php.inc @@ -1,6 +1,6 @@