Passed
Pull Request — master (#221)
by
unknown
03:06
created

Foo::removeManyToMany()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 2
c 1
b 0
f 1
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Zenstruck\Foundry\Tests\Fixtures\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\Common\Collections\Collection;
7
use Doctrine\ORM\Mapping as ORM;
8
9
/**
10
 * @ORM\Entity
11
 * @ORM\Table(name="foos")
12
 */
13
class Foo
14
{
15
    /**
16
     * @ORM\Id
17
     * @ORM\GeneratedValue
18
     * @ORM\Column(type="integer")
19
     */
20
    private $id;
21
22
    /**
23
     * @ORM\OneToOne(targetEntity=Category::class, cascade={"persist", "remove"})
24
     * @ORM\JoinColumn(nullable=false)
25
     */
26
    private $oneToOne;
27
28
    /**
29
     * @ORM\OneToMany(targetEntity=Category::class, mappedBy="foo")
30
     */
31
    private $oneToMany;
32
33
    /**
34
     * @ORM\ManyToOne(targetEntity=Category::class)
35
     * @ORM\JoinColumn(nullable=false)
36
     */
37
    private $manyToOne;
38
39
    /**
40
     * @ORM\ManyToMany(targetEntity=Category::class)
41
     */
42
    private $manyToMany;
43
44
    public function __construct()
45
    {
46
        $this->oneToMany = new ArrayCollection();
47
        $this->manyToMany = new ArrayCollection();
48
    }
49
50
    public function getId(): ?int
51
    {
52
        return $this->id;
53
    }
54
55
    public function getOneToOne(): ?Category
56
    {
57
        return $this->oneToOne;
58
    }
59
60
    public function setOneToOne(Category $oneToOne): self
61
    {
62
        $this->oneToOne = $oneToOne;
63
64
        return $this;
65
    }
66
67
    /**
68
     * @return Collection|Category[]
69
     */
70
    public function getOneToMany(): Collection
71
    {
72
        return $this->oneToMany;
73
    }
74
75
    public function addOneToMany(Category $oneToMany): self
76
    {
77
        if (!$this->oneToMany->contains($oneToMany)) {
78
            $this->oneToMany[] = $oneToMany;
79
            $oneToMany->setFoo($this);
0 ignored issues
show
Bug introduced by
The method setFoo() does not exist on Zenstruck\Foundry\Tests\Fixtures\Entity\Category. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

79
            $oneToMany->/** @scrutinizer ignore-call */ 
80
                        setFoo($this);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
80
        }
81
82
        return $this;
83
    }
84
85
    public function removeOneToMany(Category $oneToMany): self
86
    {
87
        if ($this->oneToMany->removeElement($oneToMany)) {
88
            // set the owning side to null (unless already changed)
89
            if ($oneToMany->getFoo() === $this) {
0 ignored issues
show
Bug introduced by
The method getFoo() does not exist on Zenstruck\Foundry\Tests\Fixtures\Entity\Category. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

89
            if ($oneToMany->/** @scrutinizer ignore-call */ getFoo() === $this) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
90
                $oneToMany->setFoo(null);
91
            }
92
        }
93
94
        return $this;
95
    }
96
97
    public function getManyToOne(): ?Category
98
    {
99
        return $this->manyToOne;
100
    }
101
102
    public function setManyToOne(?Category $manyToOne): self
103
    {
104
        $this->manyToOne = $manyToOne;
105
106
        return $this;
107
    }
108
109
    /**
110
     * @return Collection|Category[]
111
     */
112
    public function getManyToMany(): Collection
113
    {
114
        return $this->manyToMany;
115
    }
116
117
    public function addManyToMany(Category $manyToMany): self
118
    {
119
        if (!$this->manyToMany->contains($manyToMany)) {
120
            $this->manyToMany[] = $manyToMany;
121
        }
122
123
        return $this;
124
    }
125
126
    public function removeManyToMany(Category $manyToMany): self
127
    {
128
        $this->manyToMany->removeElement($manyToMany);
129
130
        return $this;
131
    }
132
}
133