Skip to content

fix(test): replace Collection|iterable with Collection and add appropriate PHPDoc tags #7303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ parameters:
message: '#but database expects#'
paths:
- tests/Fixtures/TestBundle/Entity/
- '#Cannot call method add\(\) on iterable.#'
-
message: '#is never read, only written.#'
paths:
Expand Down
10 changes: 8 additions & 2 deletions src/Doctrine/Common/Tests/Fixtures/TestBundle/Entity/Dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ class Dummy
#[ORM\ManyToOne(targetEntity: RelatedDummy::class)]
public ?RelatedDummy $relatedDummy = null;

/**
* @var Collection<int, RelatedDummy>
*/
#[ORM\ManyToMany(targetEntity: RelatedDummy::class)]
public Collection|iterable $relatedDummies;
public Collection $relatedDummies;

/**
* @var array|null serialize data
Expand Down Expand Up @@ -302,7 +305,10 @@ public function getDummy()
return $this->dummy;
}

public function getRelatedDummies(): Collection|iterable
/**
* @return Collection<int, RelatedDummy>
*/
public function getRelatedDummies(): Collection
{
return $this->relatedDummies;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ class RelatedDummy extends ParentDummy implements \Stringable
#[Groups(['barcelona', 'chicago', 'friends'])]
public ?ThirdLevel $thirdLevel = null;

/**
* @var Collection<int, RelatedToDummyFriend>
*/
#[ORM\OneToMany(targetEntity: RelatedToDummyFriend::class, cascade: ['persist'], mappedBy: 'relatedDummy')]
#[Groups(['fakemanytomany', 'friends'])]
public Collection|iterable $relatedToDummyFriend;
public Collection $relatedToDummyFriend;

/**
* @var bool|null A dummy bool
Expand Down Expand Up @@ -168,8 +171,10 @@ public function setThirdLevel(?ThirdLevel $thirdLevel = null): void

/**
* Get relatedToDummyFriend.
*
* @return Collection<int, RelatedToDummyFriend>
*/
public function getRelatedToDummyFriend(): Collection|iterable
public function getRelatedToDummyFriend(): Collection
{
return $this->relatedToDummyFriend;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Doctrine/Odm/Tests/Fixtures/Document/Dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ class Dummy
public $dummyPrice;
#[ODM\ReferenceOne(targetDocument: RelatedDummy::class, storeAs: 'id', nullable: true)]
public ?RelatedDummy $relatedDummy = null;
/**
* @return Collection<int, RelatedDummy>
*/
#[ODM\ReferenceMany(targetDocument: RelatedDummy::class, storeAs: 'id', nullable: true)]
public Collection|iterable $relatedDummies;
public Collection $relatedDummies;
#[ODM\Field(type: 'hash', nullable: true)]
public array $jsonData = [];
#[ODM\Field(type: 'collection', nullable: true)]
Expand Down
9 changes: 7 additions & 2 deletions src/Doctrine/Odm/Tests/Fixtures/Document/RelatedDummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ class RelatedDummy extends ParentDummy implements \Stringable
public $dummyDate;
#[ODM\ReferenceOne(targetDocument: ThirdLevel::class, cascade: ['persist'], nullable: true, storeAs: 'id', inversedBy: 'relatedDummies')]
public ?ThirdLevel $thirdLevel = null;
/**
* @var Collection<int, RelatedToDummyFriend>
*/
#[ODM\ReferenceMany(targetDocument: RelatedToDummyFriend::class, cascade: ['persist'], mappedBy: 'relatedDummy', storeAs: 'id')]
public Collection|iterable $relatedToDummyFriend;
public Collection $relatedToDummyFriend;
#[ODM\Field(type: 'bool')]
public ?bool $dummyBoolean = null;
#[ODM\EmbedOne(targetDocument: EmbeddableDummy::class)]
Expand Down Expand Up @@ -120,8 +123,10 @@ public function setThirdLevel(?ThirdLevel $thirdLevel = null): void

/**
* Get relatedToDummyFriend.
*
* @return Collection<int, RelatedToDummyFriend>
*/
public function getRelatedToDummyFriend(): Collection|iterable
public function getRelatedToDummyFriend(): Collection
{
return $this->relatedToDummyFriend;
}
Expand Down
10 changes: 8 additions & 2 deletions src/Doctrine/Orm/Tests/Fixtures/Entity/Dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ class Dummy
#[ORM\ManyToOne(targetEntity: RelatedDummy::class)]
public ?RelatedDummy $relatedDummy = null;

/**
* @var Collection<int, RelatedDummy>
*/
#[ORM\ManyToMany(targetEntity: RelatedDummy::class)]
public Collection|iterable $relatedDummies;
public Collection $relatedDummies;

/**
* @var array|null serialize data
Expand Down Expand Up @@ -305,7 +308,10 @@ public function getDummy()
return $this->dummy;
}

public function getRelatedDummies(): Collection|iterable
/**
* @return Collection<int, RelatedDummy>
*/
public function getRelatedDummies(): Collection
{
return $this->relatedDummies;
}
Expand Down
9 changes: 7 additions & 2 deletions src/Doctrine/Orm/Tests/Fixtures/Entity/RelatedDummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ class RelatedDummy extends ParentDummy implements \Stringable
#[Groups(['barcelona', 'chicago', 'friends'])]
public ?ThirdLevel $thirdLevel = null;

/**
* @var Collection<int, RelatedToDummyFriend>
*/
#[ORM\OneToMany(targetEntity: RelatedToDummyFriend::class, cascade: ['persist'], mappedBy: 'relatedDummy')]
#[Groups(['fakemanytomany', 'friends'])]
public Collection|iterable $relatedToDummyFriend;
public Collection $relatedToDummyFriend;

#[ORM\Column(enumType: DummyBackedEnum::class, nullable: true)]
public DummyBackedEnum $dummyBackedEnum;
Expand Down Expand Up @@ -179,8 +182,10 @@ public function setThirdLevel(?ThirdLevel $thirdLevel = null): void

/**
* Get relatedToDummyFriend.
*
* @return Collection<int, RelatedToDummyFriend>
*/
public function getRelatedToDummyFriend(): Collection|iterable
public function getRelatedToDummyFriend(): Collection
{
return $this->relatedToDummyFriend;
}
Expand Down
5 changes: 0 additions & 5 deletions src/OpenApi/Tests/Fixtures/Dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,6 @@ public function setRelatedDummy(RelatedDummy $relatedDummy): void
$this->relatedDummy = $relatedDummy;
}

public function addRelatedDummy(RelatedDummy $relatedDummy): void
{
$this->relatedDummies->add($relatedDummy);
}

public function isDummyBoolean(): ?bool
{
return $this->dummyBoolean;
Expand Down
4 changes: 2 additions & 2 deletions src/Serializer/Tests/Fixtures/ApiResource/Dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Dummy
#[ApiProperty(push: true)]
public ?RelatedDummy $relatedDummy = null;

public Collection|iterable $relatedDummies;
public Collection $relatedDummies;

/**
* @var Collection<int, RelatedDummy>
Expand Down Expand Up @@ -249,7 +249,7 @@ public function getDummy()
return $this->dummy;
}

public function getRelatedDummies(): Collection|iterable
public function getRelatedDummies(): Collection
{
return $this->relatedDummies;
}
Expand Down
10 changes: 8 additions & 2 deletions tests/Fixtures/TestBundle/Document/Answer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ class Answer
#[Serializer\Groups(['foobar'])]
#[ODM\ReferenceOne(targetDocument: Question::class, mappedBy: 'answer')]
private ?Question $question = null;

/**
* @var Collection<int, Question>
*/
#[Serializer\Groups(['foobar'])]
#[ODM\ReferenceMany(targetDocument: Question::class, mappedBy: 'answer')]
private Collection|iterable $relatedQuestions;
private Collection $relatedQuestions;

public function __construct()
{
Expand Down Expand Up @@ -98,8 +102,10 @@ public function getQuestion(): ?Question

/**
* Get related question.
*
* @return Collection<int, Question>
*/
public function getRelatedQuestions(): Collection|iterable
public function getRelatedQuestions(): Collection
{
return $this->relatedQuestions;
}
Expand Down
6 changes: 5 additions & 1 deletion tests/Fixtures/TestBundle/Document/CircularReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ class CircularReference
#[Groups(['circular'])]
#[ODM\ReferenceOne(targetDocument: self::class, inversedBy: 'children')]
public $parent;

/**
* @var Collection<int, self>
*/
#[Groups(['circular'])]
#[ODM\ReferenceMany(targetDocument: self::class, mappedBy: 'parent')]
public Collection|iterable $children;
public Collection $children;

public function __construct()
{
Expand Down
6 changes: 5 additions & 1 deletion tests/Fixtures/TestBundle/Document/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ class Customer
#[Groups(['order_read'])]
#[ODM\Field(type: 'string')]
public $name;

/**
* @var Collection<int, Address>
*/
#[Groups(['order_read'])]
#[ODM\ReferenceMany(targetDocument: Address::class)]
public Collection|iterable $addresses;
public Collection $addresses;

public function __construct()
{
Expand Down
6 changes: 5 additions & 1 deletion tests/Fixtures/TestBundle/Document/Dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,12 @@ class Dummy
public $dummyPrice;
#[ODM\ReferenceOne(targetDocument: RelatedDummy::class, storeAs: 'id', nullable: true)]
public ?RelatedDummy $relatedDummy = null;

/**
* @var Collection<int, RelatedDummy>
*/
#[ODM\ReferenceMany(targetDocument: RelatedDummy::class, storeAs: 'id', nullable: true)]
public Collection|iterable $relatedDummies;
public Collection $relatedDummies;
#[ODM\Field(type: 'hash', nullable: true)]
public array $jsonData = [];
#[ODM\Field(type: 'collection', nullable: true)]
Expand Down
16 changes: 13 additions & 3 deletions tests/Fixtures/TestBundle/Document/DummyAggregateOffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ class DummyAggregateOffer
*/
#[ODM\Id(strategy: 'INCREMENT', type: 'int')]
private ?int $id = null;

/**
* @var Collection<int, DummyOffer>
*/
#[ODM\ReferenceMany(targetDocument: DummyOffer::class, mappedBy: 'aggregate', cascade: ['persist'])]
private Collection|iterable $offers;
private Collection $offers;
/**
* @var DummyProduct The dummy product
*/
Expand All @@ -56,12 +60,18 @@ public function __construct()
$this->offers = new ArrayCollection();
}

public function getOffers(): Collection|iterable
/**
* @return Collection<int, DummyOffer>
*/
public function getOffers(): Collection
{
return $this->offers;
}

public function setOffers(Collection|iterable $offers): void
/**
* @param Collection<int, DummyOffer> $offers
*/
public function setOffers(Collection $offers): void
{
$this->offers = $offers;
}
Expand Down
32 changes: 26 additions & 6 deletions tests/Fixtures/TestBundle/Document/DummyProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,23 @@ class DummyProduct
*/
#[ODM\Id(strategy: 'None', type: 'int')]
private ?int $id = null;

/**
* @var Collection<int, DummyAggregateOffer>
*/
#[ODM\ReferenceMany(targetDocument: DummyAggregateOffer::class, mappedBy: 'product', cascade: ['persist'])]
private Collection|iterable $offers;
private Collection $offers;
/**
* @var string The tour name
*/
#[ODM\Field]
private string $name;

/**
* @var Collection<int, self>
*/
#[ODM\ReferenceMany(targetDocument: self::class, mappedBy: 'parent')]
private Collection|iterable $relatedProducts;
private Collection $relatedProducts;
#[ODM\ReferenceOne(targetDocument: self::class, inversedBy: 'relatedProducts')]
private $parent;

Expand All @@ -55,12 +63,18 @@ public function __construct()
$this->relatedProducts = new ArrayCollection();
}

public function getOffers(): Collection|iterable
/**
* @return Collection<int, DummyAggregateOffer>
*/
public function getOffers(): Collection
{
return $this->offers;
}

public function setOffers(Collection|iterable $offers): void
/**
* @param Collection<int, DummyAggregateOffer> $offers
*/
public function setOffers(Collection $offers): void
{
$this->offers = $offers;
}
Expand Down Expand Up @@ -91,12 +105,18 @@ public function setName(string $name): void
$this->name = $name;
}

public function getRelatedProducts(): Collection|iterable
/**
* @return Collection<int, self>
*/
public function getRelatedProducts(): Collection
{
return $this->relatedProducts;
}

public function setRelatedProducts(Collection|iterable $relatedProducts): void
/**
* @param Collection<int, self> $relatedProducts
*/
public function setRelatedProducts(Collection $relatedProducts): void
{
$this->relatedProducts = $relatedProducts;
}
Expand Down
9 changes: 7 additions & 2 deletions tests/Fixtures/TestBundle/Document/OptionalRequiredDummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ class OptionalRequiredDummy
#[Groups(['barcelona', 'chicago', 'friends'])]
public ThirdLevel $thirdLevelRequired;

/**
* @var Collection<int, RelatedToDummyFriend>
*/
#[ODM\ReferenceMany(targetDocument: RelatedToDummyFriend::class, mappedBy: 'relatedDummy')]
#[Groups(['fakemanytomany', 'friends'])]
public Collection|iterable $relatedToDummyFriend;
public Collection $relatedToDummyFriend;

public function __construct()
{
Expand Down Expand Up @@ -89,8 +92,10 @@ public function setThirdLevelRequired(ThirdLevel $thirdLevelRequired): void

/**
* Get relatedToDummyFriend.
*
* @return Collection<int, RelatedToDummyFriend>
*/
public function getRelatedToDummyFriend(): Collection|iterable
public function getRelatedToDummyFriend(): Collection
{
return $this->relatedToDummyFriend;
}
Expand Down
10 changes: 8 additions & 2 deletions tests/Fixtures/TestBundle/Document/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,18 @@ class Person
#[Groups(['people.pets'])]
public array $academicGrades = [];

/**
* @var Collection<int, PersonToPet>
*/
#[Groups(['people.pets'])]
#[ODM\ReferenceMany(targetDocument: PersonToPet::class, mappedBy: 'person')]
public Collection|iterable $pets;
public Collection $pets;

/**
* @var Collection<int, Greeting>
*/
#[ODM\ReferenceMany(targetDocument: Greeting::class, mappedBy: 'sender')]
public Collection|iterable|null $sentGreetings = null;
public Collection $sentGreetings;

public function __construct()
{
Expand Down
Loading
Loading