Skip to content

Commit 0126e5c

Browse files
authored
Merge pull request #1136 from faibl/main
use method add() instead of [] in collection adder-method
2 parents 28319be + d2622b7 commit 0126e5c

File tree

12 files changed

+17
-18
lines changed

12 files changed

+17
-18
lines changed

src/Util/ClassSourceManipulator.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -615,11 +615,10 @@ private function addCollectionRelation(BaseCollectionRelation $relation): void
615615

616616
// append the item
617617
$ifNotContainsStmt->stmts[] = new Node\Stmt\Expression(
618-
new Node\Expr\Assign(
619-
new Node\Expr\ArrayDimFetch(
620-
new Node\Expr\PropertyFetch(new Node\Expr\Variable('this'), $relation->getPropertyName())
621-
),
622-
new Node\Expr\Variable($argName)
618+
new Node\Expr\MethodCall(
619+
new Node\Expr\PropertyFetch(new Node\Expr\Variable('this'), $relation->getPropertyName()),
620+
'add',
621+
[new Node\Expr\Variable($argName)]
623622
));
624623

625624
// set the owning side of the relationship

tests/Doctrine/fixtures/expected_no_overwrite/src/Entity/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function getTags(): Collection
6565
public function addTag(Tag $tag): self
6666
{
6767
if (!$this->tags->contains($tag)) {
68-
$this->tags[] = $tag;
68+
$this->tags->add($tag);
6969
}
7070

7171
return $this;

tests/Doctrine/fixtures/expected_no_overwrite/src/Entity/User.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function getAvatars(): Collection
5656
public function addAvatar(UserAvatar $avatar): self
5757
{
5858
if (!$this->avatars->contains($avatar)) {
59-
$this->avatars[] = $avatar;
59+
$this->avatars->add($avatar);
6060
$avatar->setUser($this);
6161
}
6262

@@ -91,7 +91,7 @@ public function getTags(): Collection
9191
public function addTag(Tag $tag): self
9292
{
9393
if (!$this->tags->contains($tag)) {
94-
$this->tags[] = $tag;
94+
$this->tags->add($tag);
9595
}
9696

9797
return $this;

tests/Doctrine/fixtures/expected_overwrite/src/Entity/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function getTags(): Collection
6565
public function addTag(Tag $tag): self
6666
{
6767
if (!$this->tags->contains($tag)) {
68-
$this->tags[] = $tag;
68+
$this->tags->add($tag);
6969
}
7070

7171
return $this;

tests/Doctrine/fixtures/expected_overwrite/src/Entity/User.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function getAvatars(): Collection
6767
public function addAvatar(UserAvatar $avatar): self
6868
{
6969
if (!$this->avatars->contains($avatar)) {
70-
$this->avatars[] = $avatar;
70+
$this->avatars->add($avatar);
7171
$avatar->setUser($this);
7272
}
7373

@@ -102,7 +102,7 @@ public function getTags(): Collection
102102
public function addTag(Tag $tag): self
103103
{
104104
if (!$this->tags->contains($tag)) {
105-
$this->tags[] = $tag;
105+
$this->tags->add($tag);
106106
}
107107

108108
return $this;

tests/Doctrine/fixtures/expected_xml/src/Entity/UserXml.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function getAvatars(): Collection
4747
public function addAvatar(UserAvatar $avatar): self
4848
{
4949
if (!$this->avatars->contains($avatar)) {
50-
$this->avatars[] = $avatar;
50+
$this->avatars->add($avatar);
5151
$avatar->setUser($this);
5252
}
5353

tests/Util/fixtures/add_many_to_many_relation/User_simple_inverse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function getRecipes(): Collection
3838
public function addRecipe(Recipe $recipe): self
3939
{
4040
if (!$this->recipes->contains($recipe)) {
41-
$this->recipes[] = $recipe;
41+
$this->recipes->add($recipe);
4242
$recipe->addFood($this);
4343
}
4444

tests/Util/fixtures/add_many_to_many_relation/User_simple_no_inverse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function getRecipes(): Collection
3838
public function addRecipe(Recipe $recipe): self
3939
{
4040
if (!$this->recipes->contains($recipe)) {
41-
$this->recipes[] = $recipe;
41+
$this->recipes->add($recipe);
4242
}
4343

4444
return $this;

tests/Util/fixtures/add_many_to_many_relation/User_simple_owning.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function getRecipes(): Collection
3838
public function addRecipe(Recipe $recipe): self
3939
{
4040
if (!$this->recipes->contains($recipe)) {
41-
$this->recipes[] = $recipe;
41+
$this->recipes->add($recipe);
4242
}
4343

4444
return $this;

tests/Util/fixtures/add_one_to_many_relation/User_simple.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function getAvatarPhotos(): Collection
3838
public function addAvatarPhoto(UserAvatarPhoto $avatarPhoto): self
3939
{
4040
if (!$this->avatarPhotos->contains($avatarPhoto)) {
41-
$this->avatarPhotos[] = $avatarPhoto;
41+
$this->avatarPhotos->add($avatarPhoto);
4242
$avatarPhoto->setUser($this);
4343
}
4444

tests/Util/fixtures/add_one_to_many_relation/User_simple_orphan_removal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function getAvatarPhotos(): Collection
3838
public function addAvatarPhoto(UserAvatarPhoto $avatarPhoto): self
3939
{
4040
if (!$this->avatarPhotos->contains($avatarPhoto)) {
41-
$this->avatarPhotos[] = $avatarPhoto;
41+
$this->avatarPhotos->add($avatarPhoto);
4242
$avatarPhoto->setUser($this);
4343
}
4444

tests/Util/fixtures/add_one_to_many_relation/User_with_use_statements.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function getAvatarPhotos(): Collection
4141
public function addAvatarPhoto(UserAvatarPhoto $avatarPhoto): self
4242
{
4343
if (!$this->avatarPhotos->contains($avatarPhoto)) {
44-
$this->avatarPhotos[] = $avatarPhoto;
44+
$this->avatarPhotos->add($avatarPhoto);
4545
$avatarPhoto->setUser($this);
4646
}
4747

0 commit comments

Comments
 (0)