Skip to content

Commit 563e40c

Browse files
vincentchalamonalanpoulain
authored andcommitted
chore: set doctrine collections typehint
1 parent 0dc81a0 commit 563e40c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+150
-134
lines changed

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ parameters:
4343
message: '#but database expects#'
4444
paths:
4545
- tests/Fixtures/TestBundle/Entity/
46+
- '#Cannot call method add\(\) on iterable.#'
4647
-
4748
message: '#is never read, only written.#'
4849
paths:

tests/Fixtures/TestBundle/Document/AbsoluteUrlRelationDummy.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\Api\UrlGeneratorInterface;
1717
use ApiPlatform\Metadata\ApiResource;
1818
use Doctrine\Common\Collections\ArrayCollection;
19+
use Doctrine\Common\Collections\Collection;
1920
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
2021

2122
#[ApiResource(urlGenerationStrategy: UrlGeneratorInterface::ABS_URL)]
@@ -25,7 +26,7 @@ class AbsoluteUrlRelationDummy
2526
#[ODM\Id(strategy: 'INCREMENT', type: 'int')]
2627
private $id;
2728
#[ODM\ReferenceMany(targetDocument: AbsoluteUrlDummy::class, mappedBy: 'absoluteUrlRelationDummy')]
28-
public $absoluteUrlDummies;
29+
public Collection|iterable $absoluteUrlDummies;
2930

3031
public function __construct()
3132
{

tests/Fixtures/TestBundle/Document/Answer.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use ApiPlatform\Metadata\Patch;
2222
use ApiPlatform\Metadata\Put;
2323
use Doctrine\Common\Collections\ArrayCollection;
24+
use Doctrine\Common\Collections\Collection;
2425
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
2526
use Symfony\Component\Serializer\Annotation as Serializer;
2627

@@ -44,7 +45,7 @@ class Answer
4445
private ?Question $question = null;
4546
#[Serializer\Groups(['foobar'])]
4647
#[ODM\ReferenceMany(targetDocument: Question::class, mappedBy: 'answer')]
47-
private $relatedQuestions;
48+
private Collection|iterable $relatedQuestions;
4849

4950
public function __construct()
5051
{
@@ -98,7 +99,7 @@ public function getQuestion(): ?Question
9899
/**
99100
* Get related question.
100101
*/
101-
public function getRelatedQuestions(): iterable
102+
public function getRelatedQuestions(): Collection|iterable
102103
{
103104
return $this->relatedQuestions;
104105
}

tests/Fixtures/TestBundle/Document/CircularReference.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use ApiPlatform\Metadata\ApiResource;
1717
use Doctrine\Common\Collections\ArrayCollection;
18+
use Doctrine\Common\Collections\Collection;
1819
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
1920
use Symfony\Component\Serializer\Annotation\Groups;
2021

@@ -34,7 +35,7 @@ class CircularReference
3435
public $parent;
3536
#[Groups(['circular'])]
3637
#[ODM\ReferenceMany(targetDocument: self::class, mappedBy: 'parent')]
37-
public $children;
38+
public Collection|iterable $children;
3839

3940
public function __construct()
4041
{

tests/Fixtures/TestBundle/Document/CompositeItem.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use ApiPlatform\Metadata\ApiResource;
1717
use Doctrine\Common\Collections\ArrayCollection;
18+
use Doctrine\Common\Collections\Collection;
1819
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
1920
use Symfony\Component\Serializer\Annotation\Groups;
2021

@@ -32,7 +33,7 @@ class CompositeItem implements \Stringable
3233
private ?string $field1 = null;
3334
#[Groups(['default'])]
3435
#[ODM\ReferenceMany(targetDocument: CompositeRelation::class, mappedBy: 'compositeItem')]
35-
private $compositeValues;
36+
private Collection|iterable $compositeValues;
3637

3738
public function __construct()
3839
{
@@ -66,7 +67,7 @@ public function setField1(?string $field1 = null): void
6667
/**
6768
* Gets compositeValues.
6869
*/
69-
public function getCompositeValues(): iterable
70+
public function getCompositeValues(): Collection|iterable
7071
{
7172
return $this->compositeValues;
7273
}

tests/Fixtures/TestBundle/Document/Content.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Content implements \JsonSerializable
3232
* @var Collection<Field>
3333
*/
3434
#[ODM\ReferenceMany(targetDocument: Field::class, mappedBy: 'content', strategy: 'set', cascade: ['persist'])]
35-
private $fields;
35+
private Collection|iterable $fields;
3636
#[ODM\Field(type: 'string')]
3737
private string $status = ContentStatus::DRAFT;
3838

tests/Fixtures/TestBundle/Document/Customer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use ApiPlatform\Metadata\ApiResource;
1717
use Doctrine\Common\Collections\ArrayCollection;
18+
use Doctrine\Common\Collections\Collection;
1819
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
1920
use Symfony\Component\Serializer\Annotation\Groups;
2021

@@ -30,7 +31,7 @@ class Customer
3031
public $name;
3132
#[Groups(['order_read'])]
3233
#[ODM\ReferenceMany(targetDocument: Address::class)]
33-
public $addresses;
34+
public Collection|iterable $addresses;
3435

3536
public function __construct()
3637
{

tests/Fixtures/TestBundle/Document/Dummy.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use ApiPlatform\Metadata\Get;
1919
use ApiPlatform\Metadata\Link;
2020
use Doctrine\Common\Collections\ArrayCollection;
21+
use Doctrine\Common\Collections\Collection;
2122
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
2223
use Symfony\Component\Validator\Constraints as Assert;
2324

@@ -87,7 +88,7 @@ class Dummy
8788
#[ODM\ReferenceOne(targetDocument: RelatedDummy::class, storeAs: 'id', nullable: true)]
8889
public ?RelatedDummy $relatedDummy = null;
8990
#[ODM\ReferenceMany(targetDocument: RelatedDummy::class, storeAs: 'id', nullable: true)]
90-
public $relatedDummies;
91+
public Collection|iterable $relatedDummies;
9192
#[ODM\Field(type: 'hash', nullable: true)]
9293
public array $jsonData = [];
9394
#[ODM\Field(type: 'collection', nullable: true)]

tests/Fixtures/TestBundle/Document/DummyAggregateOffer.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use ApiPlatform\Metadata\GetCollection;
1818
use ApiPlatform\Metadata\Link;
1919
use Doctrine\Common\Collections\ArrayCollection;
20+
use Doctrine\Common\Collections\Collection;
2021
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
2122

2223
/**
@@ -38,7 +39,7 @@ class DummyAggregateOffer
3839
#[ODM\Id(strategy: 'INCREMENT', type: 'int')]
3940
private ?int $id = null;
4041
#[ODM\ReferenceMany(targetDocument: DummyOffer::class, mappedBy: 'aggregate', cascade: ['persist'])]
41-
private $offers;
42+
private Collection|iterable $offers;
4243
/**
4344
* @var DummyProduct The dummy product
4445
*/
@@ -55,12 +56,12 @@ public function __construct()
5556
$this->offers = new ArrayCollection();
5657
}
5758

58-
public function getOffers(): iterable
59+
public function getOffers(): Collection|iterable
5960
{
6061
return $this->offers;
6162
}
6263

63-
public function setOffers($offers): void
64+
public function setOffers(Collection|iterable $offers): void
6465
{
6566
$this->offers = $offers;
6667
}

tests/Fixtures/TestBundle/Document/DummyCar.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use ApiPlatform\Serializer\Filter\GroupFilter;
2727
use ApiPlatform\Serializer\Filter\PropertyFilter;
2828
use Doctrine\Common\Collections\ArrayCollection;
29+
use Doctrine\Common\Collections\Collection;
2930
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
3031
use Symfony\Component\Serializer\Annotation as Serializer;
3132

@@ -43,19 +44,19 @@ class DummyCar
4344
#[ApiFilter(SearchFilter::class, properties: ['colors.prop' => 'ipartial', 'colors' => 'exact'])]
4445
#[Serializer\Groups(['colors'])]
4546
#[ODM\ReferenceMany(targetDocument: DummyCarColor::class, mappedBy: 'car')]
46-
private $colors;
47+
private Collection|iterable $colors;
4748
#[ApiFilter(SearchFilter::class, strategy: 'exact')]
4849
#[Serializer\Groups(['colors'])]
4950
#[ODM\ReferenceMany(targetDocument: DummyCarColor::class, mappedBy: 'car')]
50-
private $secondColors;
51+
private Collection|iterable $secondColors;
5152
#[ApiFilter(SearchFilter::class, strategy: 'exact')]
5253
#[Serializer\Groups(['colors'])]
5354
#[ODM\ReferenceMany(targetDocument: DummyCarColor::class, mappedBy: 'car')]
54-
private $thirdColors;
55+
private Collection|iterable $thirdColors;
5556
#[ApiFilter(SearchFilter::class, strategy: 'exact')]
5657
#[Serializer\Groups(['colors'])]
5758
#[ODM\ReferenceMany(targetDocument: UuidIdentifierDummy::class)]
58-
private $uuid;
59+
private Collection|iterable $uuid;
5960
#[ApiFilter(SearchFilter::class, strategy: 'partial')]
6061
#[ODM\Field(type: 'string')]
6162
private ?string $name = null;
@@ -81,44 +82,44 @@ public function getId(): ?int
8182
return $this->id;
8283
}
8384

84-
public function getColors(): iterable
85+
public function getColors(): Collection|iterable
8586
{
8687
return $this->colors;
8788
}
8889

89-
public function setColors($colors): self
90+
public function setColors(Collection|iterable $colors): self
9091
{
9192
$this->colors = $colors;
9293

9394
return $this;
9495
}
9596

96-
public function getSecondColors(): iterable
97+
public function getSecondColors(): Collection|iterable
9798
{
9899
return $this->secondColors;
99100
}
100101

101-
public function setSecondColors($secondColors): void
102+
public function setSecondColors(Collection|iterable $secondColors): void
102103
{
103104
$this->secondColors = $secondColors;
104105
}
105106

106-
public function getThirdColors(): iterable
107+
public function getThirdColors(): Collection|iterable
107108
{
108109
return $this->thirdColors;
109110
}
110111

111-
public function setThirdColors($thirdColors): void
112+
public function setThirdColors(Collection|iterable $thirdColors): void
112113
{
113114
$this->thirdColors = $thirdColors;
114115
}
115116

116-
public function getUuid(): iterable
117+
public function getUuid(): Collection|iterable
117118
{
118119
return $this->uuid;
119120
}
120121

121-
public function setUuid($uuid): void
122+
public function setUuid(Collection|iterable $uuid): void
122123
{
123124
$this->uuid = $uuid;
124125
}

0 commit comments

Comments
 (0)