Skip to content

Commit d2622b7

Browse files
author
HKandulla
committed
use method add() instead of [] in collection adder-method
1 parent 37defa0 commit d2622b7

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
@@ -567,11 +567,10 @@ private function addCollectionRelation(BaseCollectionRelation $relation): void
567567

568568
// append the item
569569
$ifNotContainsStmt->stmts[] = new Node\Stmt\Expression(
570-
new Node\Expr\Assign(
571-
new Node\Expr\ArrayDimFetch(
572-
new Node\Expr\PropertyFetch(new Node\Expr\Variable('this'), $relation->getPropertyName())
573-
),
574-
new Node\Expr\Variable($argName)
570+
new Node\Expr\MethodCall(
571+
new Node\Expr\PropertyFetch(new Node\Expr\Variable('this'), $relation->getPropertyName()),
572+
'add',
573+
[new Node\Expr\Variable($argName)]
575574
));
576575

577576
// 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
@@ -40,7 +40,7 @@ public function getAvatarPhotos(): Collection
4040
public function addAvatarPhoto(UserAvatarPhoto $avatarPhoto): self
4141
{
4242
if (!$this->avatarPhotos->contains($avatarPhoto)) {
43-
$this->avatarPhotos[] = $avatarPhoto;
43+
$this->avatarPhotos->add($avatarPhoto);
4444
$avatarPhoto->setUser($this);
4545
}
4646

0 commit comments

Comments
 (0)