Skip to content

Commit

Permalink
[make:entity] Add PHPDoc var type for Collections
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rdex committed Jan 29, 2024
1 parent 05be7f0 commit 6afc415
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Util/ClassSourceManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,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<int, %s>', $collectionTypeHint, $typeHint)],
propertyType: $collectionTypeHint,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class Client extends BaseClient
#[ORM\Column]
private ?string $apiKey = null;

/**
* @var Collection<int, Tag>
*/
#[ORM\ManyToMany(targetEntity: Tag::class)]
private Collection $tags;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ class User
#[ORM\Column]
private ?int $id = null;

/**
* @var Collection<int, UserAvatar>
*/
#[ORM\OneToMany(targetEntity: UserAvatar::class, mappedBy: 'user')]
private Collection $avatars;

#[ORM\OneToOne(mappedBy: 'user')]
private ?UserProfile $userProfile = null;

/**
* @var Collection<int, Tag>
*/
#[ORM\ManyToMany(targetEntity: Tag::class)]
private Collection $tags;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class Client extends BaseClient
#[ORM\Column]
private ?string $apiKey = null;

/**
* @var Collection<int, Tag>
*/
#[ORM\ManyToMany(targetEntity: Tag::class)]
private Collection $tags;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ class User
#[ORM\Column]
private ?int $id = null;

/**
* @var Collection<int, UserAvatar>
*/
#[ORM\OneToMany(targetEntity: UserAvatar::class, mappedBy: 'user')]
private Collection $avatars;

#[ORM\OneToOne(mappedBy: 'user')]
private ?UserProfile $userProfile = null;

/**
* @var Collection<int, Tag>
*/
#[ORM\ManyToMany(targetEntity: Tag::class)]
private Collection $tags;

Expand Down
3 changes: 3 additions & 0 deletions tests/Doctrine/fixtures/expected_xml/src/Entity/UserXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class UserXml

private ?string $name = null;

/**
* @var Collection<int, UserAvatar>
*/
private Collection $avatars;

public function __construct()
Expand Down
3 changes: 3 additions & 0 deletions tests/Doctrine/fixtures/source_project/src/Entity/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Client extends BaseClient
#[ORM\Column]
private ?string $apiKey = null;

/**
* @var Collection<int, Tag>
*/
#[ORM\ManyToMany(targetEntity: Tag::class)]
private Collection $tags;

Expand Down
6 changes: 6 additions & 0 deletions tests/Doctrine/fixtures/source_project/src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ class User
#[ORM\Column]
private ?int $id = null;

/**
* @var Collection<int, UserAvatar>
*/
#[ORM\OneToMany(targetEntity: UserAvatar::class, mappedBy: 'user')]
private Collection $avatars;

#[ORM\OneToOne(mappedBy: 'user')]
private ?UserProfile $userProfile = null;

/**
* @var Collection<int, Tag>
*/
#[ORM\ManyToMany(targetEntity: Tag::class)]
private Collection $tags;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class User
#[ORM\Column()]
private ?int $id = null;

/**
* @var Collection<int, Recipe>
*/
#[ORM\ManyToMany(targetEntity: Recipe::class, mappedBy: 'foods')]
private Collection $recipes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class User
#[ORM\Column()]
private ?int $id = null;

/**
* @var Collection<int, Recipe>
*/
#[ORM\ManyToMany(targetEntity: Recipe::class)]
private Collection $recipes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class User
#[ORM\Column()]
private ?int $id = null;

/**
* @var Collection<int, Recipe>
*/
#[ORM\ManyToMany(targetEntity: Recipe::class, inversedBy: 'foods')]
private Collection $recipes;

Expand Down
3 changes: 3 additions & 0 deletions tests/Util/fixtures/add_one_to_many_relation/User_simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class User
#[ORM\Column()]
private ?int $id = null;

/**
* @var Collection<int, UserAvatarPhoto>
*/
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserAvatarPhoto::class)]
private Collection $avatarPhotos;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class User
#[ORM\Column()]
private ?int $id = null;

/**
* @var Collection<int, UserAvatarPhoto>
*/
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserAvatarPhoto::class, orphanRemoval: true)]
private Collection $avatarPhotos;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class User
#[ORM\Column()]
private ?int $id = null;

/**
* @var Collection<int, UserAvatarPhoto>
*/
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserAvatarPhoto::class)]
private Collection $avatarPhotos;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class User
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $createdAt = null;

/**
* @var Collection<int, UserAvatar>
*/
#[ORM\OneToMany(targetEntity: UserAvatar::class, mappedBy: 'user')]
private Collection $avatars;

Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/make-form/SourFood.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class SourFood
#[ORM\Column(name: 'title', length: 255)]
private ?string $title = null;

/**
* @var Collection<int, Property>
*/
#[ORM\OneToMany(targetEntity: Property::class, mappedBy: 'sourFood')]
private Collection $properties;

Expand Down

0 comments on commit 6afc415

Please sign in to comment.