Completed
Push — master ( cf207c...9dbd6f )
by Valery
08:47
created

Category::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 View Code Duplication
class Category
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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