From 593e9717c8f13fbc681bdc54a4562e03e6283f8f Mon Sep 17 00:00:00 2001 From: Anatoly Pashin Date: Thu, 6 Oct 2022 18:46:54 +0800 Subject: [PATCH 1/2] [make:entity] Add PHPDoc var type for Collections --- src/Util/ClassSourceManipulator.php | 2 ++ .../fixtures/expected_no_overwrite/src/Entity/Client.php | 3 +++ .../fixtures/expected_no_overwrite/src/Entity/User.php | 6 ++++++ .../fixtures/expected_overwrite/src/Entity/Client.php | 3 +++ .../fixtures/expected_overwrite/src/Entity/User.php | 6 ++++++ tests/Doctrine/fixtures/expected_xml/src/Entity/UserXml.php | 3 +++ .../Doctrine/fixtures/source_project/src/Entity/Client.php | 3 +++ tests/Doctrine/fixtures/source_project/src/Entity/User.php | 6 ++++++ .../add_many_to_many_relation/User_simple_inverse.php | 3 +++ .../add_many_to_many_relation/User_simple_no_inverse.php | 3 +++ .../add_many_to_many_relation/User_simple_owning.php | 3 +++ .../Util/fixtures/add_one_to_many_relation/User_simple.php | 3 +++ .../add_one_to_many_relation/User_simple_orphan_removal.php | 3 +++ .../add_one_to_many_relation/User_with_use_statements.php | 3 +++ .../make-entity/regenerate/attributes/src/Entity/User.php | 3 +++ tests/fixtures/make-form/SourFood.php | 3 +++ 16 files changed, 56 insertions(+) diff --git a/src/Util/ClassSourceManipulator.php b/src/Util/ClassSourceManipulator.php index 78365bbba..e93aae2ca 100644 --- a/src/Util/ClassSourceManipulator.php +++ b/src/Util/ClassSourceManipulator.php @@ -594,6 +594,8 @@ private function addCollectionRelation(BaseCollectionRelation $relation): void $this->addProperty( name: $relation->getPropertyName(), attributes: $attributes, + // add @var that advertises this as a collection of specific objects + comments: [sprintf('@var %s', $collectionTypeHint, $typeHint)], propertyType: $collectionTypeHint, ); diff --git a/tests/Doctrine/fixtures/expected_no_overwrite/src/Entity/Client.php b/tests/Doctrine/fixtures/expected_no_overwrite/src/Entity/Client.php index 7a3cbfd6d..10ac6310f 100644 --- a/tests/Doctrine/fixtures/expected_no_overwrite/src/Entity/Client.php +++ b/tests/Doctrine/fixtures/expected_no_overwrite/src/Entity/Client.php @@ -17,6 +17,9 @@ class Client extends BaseClient #[ORM\Column] private ?string $apiKey = null; + /** + * @var Collection + */ #[ORM\ManyToMany(targetEntity: Tag::class)] private Collection $tags; diff --git a/tests/Doctrine/fixtures/expected_no_overwrite/src/Entity/User.php b/tests/Doctrine/fixtures/expected_no_overwrite/src/Entity/User.php index d98450ad7..c75af1594 100644 --- a/tests/Doctrine/fixtures/expected_no_overwrite/src/Entity/User.php +++ b/tests/Doctrine/fixtures/expected_no_overwrite/src/Entity/User.php @@ -14,12 +14,18 @@ class User #[ORM\Column] private ?int $id = null; + /** + * @var Collection + */ #[ORM\OneToMany(targetEntity: UserAvatar::class, mappedBy: 'user')] private Collection $avatars; #[ORM\OneToOne(mappedBy: 'user')] private ?UserProfile $userProfile = null; + /** + * @var Collection + */ #[ORM\ManyToMany(targetEntity: Tag::class)] private Collection $tags; diff --git a/tests/Doctrine/fixtures/expected_overwrite/src/Entity/Client.php b/tests/Doctrine/fixtures/expected_overwrite/src/Entity/Client.php index 7a3cbfd6d..10ac6310f 100644 --- a/tests/Doctrine/fixtures/expected_overwrite/src/Entity/Client.php +++ b/tests/Doctrine/fixtures/expected_overwrite/src/Entity/Client.php @@ -17,6 +17,9 @@ class Client extends BaseClient #[ORM\Column] private ?string $apiKey = null; + /** + * @var Collection + */ #[ORM\ManyToMany(targetEntity: Tag::class)] private Collection $tags; diff --git a/tests/Doctrine/fixtures/expected_overwrite/src/Entity/User.php b/tests/Doctrine/fixtures/expected_overwrite/src/Entity/User.php index 2339dd6f8..9f19d8a72 100644 --- a/tests/Doctrine/fixtures/expected_overwrite/src/Entity/User.php +++ b/tests/Doctrine/fixtures/expected_overwrite/src/Entity/User.php @@ -14,12 +14,18 @@ class User #[ORM\Column] private ?int $id = null; + /** + * @var Collection + */ #[ORM\OneToMany(targetEntity: UserAvatar::class, mappedBy: 'user')] private Collection $avatars; #[ORM\OneToOne(mappedBy: 'user')] private ?UserProfile $userProfile = null; + /** + * @var Collection + */ #[ORM\ManyToMany(targetEntity: Tag::class)] private Collection $tags; diff --git a/tests/Doctrine/fixtures/expected_xml/src/Entity/UserXml.php b/tests/Doctrine/fixtures/expected_xml/src/Entity/UserXml.php index aa40b7ed0..4294dec59 100644 --- a/tests/Doctrine/fixtures/expected_xml/src/Entity/UserXml.php +++ b/tests/Doctrine/fixtures/expected_xml/src/Entity/UserXml.php @@ -11,6 +11,9 @@ class UserXml private ?string $name = null; + /** + * @var Collection + */ private Collection $avatars; public function __construct() diff --git a/tests/Doctrine/fixtures/source_project/src/Entity/Client.php b/tests/Doctrine/fixtures/source_project/src/Entity/Client.php index 9c03b17dc..a4bc38f32 100644 --- a/tests/Doctrine/fixtures/source_project/src/Entity/Client.php +++ b/tests/Doctrine/fixtures/source_project/src/Entity/Client.php @@ -16,6 +16,9 @@ class Client extends BaseClient #[ORM\Column] private ?string $apiKey = null; + /** + * @var Collection + */ #[ORM\ManyToMany(targetEntity: Tag::class)] private Collection $tags; diff --git a/tests/Doctrine/fixtures/source_project/src/Entity/User.php b/tests/Doctrine/fixtures/source_project/src/Entity/User.php index 4cc282545..c862918bd 100644 --- a/tests/Doctrine/fixtures/source_project/src/Entity/User.php +++ b/tests/Doctrine/fixtures/source_project/src/Entity/User.php @@ -14,12 +14,18 @@ class User #[ORM\Column] private ?int $id = null; + /** + * @var Collection + */ #[ORM\OneToMany(targetEntity: UserAvatar::class, mappedBy: 'user')] private Collection $avatars; #[ORM\OneToOne(mappedBy: 'user')] private ?UserProfile $userProfile = null; + /** + * @var Collection + */ #[ORM\ManyToMany(targetEntity: Tag::class)] private Collection $tags; diff --git a/tests/Util/fixtures/add_many_to_many_relation/User_simple_inverse.php b/tests/Util/fixtures/add_many_to_many_relation/User_simple_inverse.php index 762a033ba..83074d7e7 100644 --- a/tests/Util/fixtures/add_many_to_many_relation/User_simple_inverse.php +++ b/tests/Util/fixtures/add_many_to_many_relation/User_simple_inverse.php @@ -14,6 +14,9 @@ class User #[ORM\Column()] private ?int $id = null; + /** + * @var Collection + */ #[ORM\ManyToMany(targetEntity: Recipe::class, mappedBy: 'foods')] private Collection $recipes; diff --git a/tests/Util/fixtures/add_many_to_many_relation/User_simple_no_inverse.php b/tests/Util/fixtures/add_many_to_many_relation/User_simple_no_inverse.php index 2be35be3e..3d8f0c503 100644 --- a/tests/Util/fixtures/add_many_to_many_relation/User_simple_no_inverse.php +++ b/tests/Util/fixtures/add_many_to_many_relation/User_simple_no_inverse.php @@ -14,6 +14,9 @@ class User #[ORM\Column()] private ?int $id = null; + /** + * @var Collection + */ #[ORM\ManyToMany(targetEntity: Recipe::class)] private Collection $recipes; diff --git a/tests/Util/fixtures/add_many_to_many_relation/User_simple_owning.php b/tests/Util/fixtures/add_many_to_many_relation/User_simple_owning.php index 99e785950..37d94a4d8 100644 --- a/tests/Util/fixtures/add_many_to_many_relation/User_simple_owning.php +++ b/tests/Util/fixtures/add_many_to_many_relation/User_simple_owning.php @@ -14,6 +14,9 @@ class User #[ORM\Column()] private ?int $id = null; + /** + * @var Collection + */ #[ORM\ManyToMany(targetEntity: Recipe::class, inversedBy: 'foods')] private Collection $recipes; diff --git a/tests/Util/fixtures/add_one_to_many_relation/User_simple.php b/tests/Util/fixtures/add_one_to_many_relation/User_simple.php index 915cae2a6..54c5e8a94 100644 --- a/tests/Util/fixtures/add_one_to_many_relation/User_simple.php +++ b/tests/Util/fixtures/add_one_to_many_relation/User_simple.php @@ -14,6 +14,9 @@ class User #[ORM\Column()] private ?int $id = null; + /** + * @var Collection + */ #[ORM\OneToMany(targetEntity: UserAvatarPhoto::class, mappedBy: 'user')] private Collection $avatarPhotos; diff --git a/tests/Util/fixtures/add_one_to_many_relation/User_simple_orphan_removal.php b/tests/Util/fixtures/add_one_to_many_relation/User_simple_orphan_removal.php index effc715bf..f7b372cfe 100644 --- a/tests/Util/fixtures/add_one_to_many_relation/User_simple_orphan_removal.php +++ b/tests/Util/fixtures/add_one_to_many_relation/User_simple_orphan_removal.php @@ -14,6 +14,9 @@ class User #[ORM\Column()] private ?int $id = null; + /** + * @var Collection + */ #[ORM\OneToMany(targetEntity: UserAvatarPhoto::class, mappedBy: 'user', orphanRemoval: true)] private Collection $avatarPhotos; diff --git a/tests/Util/fixtures/add_one_to_many_relation/User_with_use_statements.php b/tests/Util/fixtures/add_one_to_many_relation/User_with_use_statements.php index bf907e58c..6f2e7219f 100644 --- a/tests/Util/fixtures/add_one_to_many_relation/User_with_use_statements.php +++ b/tests/Util/fixtures/add_one_to_many_relation/User_with_use_statements.php @@ -17,6 +17,9 @@ class User #[ORM\Column()] private ?int $id = null; + /** + * @var Collection + */ #[ORM\OneToMany(targetEntity: UserAvatarPhoto::class, mappedBy: 'user')] private Collection $avatarPhotos; diff --git a/tests/fixtures/make-entity/regenerate/attributes/src/Entity/User.php b/tests/fixtures/make-entity/regenerate/attributes/src/Entity/User.php index 752809726..b7cd19514 100644 --- a/tests/fixtures/make-entity/regenerate/attributes/src/Entity/User.php +++ b/tests/fixtures/make-entity/regenerate/attributes/src/Entity/User.php @@ -20,6 +20,9 @@ class User #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)] private ?\DateTimeInterface $createdAt = null; + /** + * @var Collection + */ #[ORM\OneToMany(targetEntity: UserAvatar::class, mappedBy: 'user')] private Collection $avatars; diff --git a/tests/fixtures/make-form/SourFood.php b/tests/fixtures/make-form/SourFood.php index eccaf553d..d1e658416 100644 --- a/tests/fixtures/make-form/SourFood.php +++ b/tests/fixtures/make-form/SourFood.php @@ -17,6 +17,9 @@ class SourFood #[ORM\Column(name: 'title', length: 255)] private ?string $title = null; + /** + * @var Collection + */ #[ORM\OneToMany(targetEntity: Property::class, mappedBy: 'sourFood')] private Collection $properties; From 9f2f69994e4cbdf0607f8d61dd76c5b2ab5f452f Mon Sep 17 00:00:00 2001 From: Anatoly Pashin Date: Thu, 28 Mar 2024 19:01:33 +0700 Subject: [PATCH 2/2] [make:entity] Add PHPDoc var type for Collections Fix legacy test fixtures --- .../fixtures/add_one_to_many_relation/legacy/User_simple.php | 3 +++ .../legacy/User_simple_orphan_removal.php | 3 +++ .../legacy/User_with_use_statements.php | 3 +++ 3 files changed, 9 insertions(+) diff --git a/tests/Util/fixtures/add_one_to_many_relation/legacy/User_simple.php b/tests/Util/fixtures/add_one_to_many_relation/legacy/User_simple.php index e742e7ef0..62db055e1 100644 --- a/tests/Util/fixtures/add_one_to_many_relation/legacy/User_simple.php +++ b/tests/Util/fixtures/add_one_to_many_relation/legacy/User_simple.php @@ -14,6 +14,9 @@ class User #[ORM\Column()] private ?int $id = null; + /** + * @var Collection + */ #[ORM\OneToMany(mappedBy: 'user', targetEntity: UserAvatarPhoto::class)] private Collection $avatarPhotos; diff --git a/tests/Util/fixtures/add_one_to_many_relation/legacy/User_simple_orphan_removal.php b/tests/Util/fixtures/add_one_to_many_relation/legacy/User_simple_orphan_removal.php index e76e70d81..9e2ab58d4 100644 --- a/tests/Util/fixtures/add_one_to_many_relation/legacy/User_simple_orphan_removal.php +++ b/tests/Util/fixtures/add_one_to_many_relation/legacy/User_simple_orphan_removal.php @@ -14,6 +14,9 @@ class User #[ORM\Column()] private ?int $id = null; + /** + * @var Collection + */ #[ORM\OneToMany(mappedBy: 'user', targetEntity: UserAvatarPhoto::class, orphanRemoval: true)] private Collection $avatarPhotos; diff --git a/tests/Util/fixtures/add_one_to_many_relation/legacy/User_with_use_statements.php b/tests/Util/fixtures/add_one_to_many_relation/legacy/User_with_use_statements.php index 698741299..845f215da 100644 --- a/tests/Util/fixtures/add_one_to_many_relation/legacy/User_with_use_statements.php +++ b/tests/Util/fixtures/add_one_to_many_relation/legacy/User_with_use_statements.php @@ -17,6 +17,9 @@ class User #[ORM\Column()] private ?int $id = null; + /** + * @var Collection + */ #[ORM\OneToMany(mappedBy: 'user', targetEntity: UserAvatarPhoto::class)] private Collection $avatarPhotos;