Category::removeProperty()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 11
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Entity;
6
7
use App\Entity\Traits\EntityIdTrait;
8
use App\Entity\Traits\EntityNameTrait;
9
use Doctrine\Common\Collections\ArrayCollection;
10
use Doctrine\Common\Collections\Collection;
11
use Doctrine\ORM\Mapping as ORM;
12
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
13
14
/**
15
 * @ORM\Entity(repositoryClass="App\Repository\CategoryRepository")
16
 * @UniqueEntity("slug")
17
 */
18
class Category
19
{
20
    use EntityIdTrait;
21
    use EntityNameTrait;
22
23
    /**
24
     * @ORM\OneToMany(targetEntity="App\Entity\Property", mappedBy="category")
25
     */
26
    private $properties;
27
28
    public function __construct()
29
    {
30
        $this->properties = new ArrayCollection();
31
    }
32
33
    public function getProperties(): Collection
34
    {
35
        return $this->properties;
36
    }
37
38
    public function addProperty(Property $property): self
39
    {
40
        if (!$this->properties->contains($property)) {
41
            $this->properties[] = $property;
42
            $property->setCategory($this);
43
        }
44
45
        return $this;
46
    }
47
48
    public function removeProperty(Property $property): self
49
    {
50
        if ($this->properties->contains($property)) {
51
            $this->properties->removeElement($property);
52
            // set the owning side to null (unless already changed)
53
            if ($property->getCategory() === $this) {
54
                $property->setCategory(null);
55
            }
56
        }
57
58
        return $this;
59
    }
60
}
61