Test Failed
Branch master (354693)
by Valery
12:29
created

Area::setLocality()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Entity;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\ORM\Mapping as ORM;
10
11
/**
12
 * @ORM\Entity(repositoryClass="App\Repository\AreaRepository")
13
 */
14
class Area
15
{
16
    /**
17
     * @ORM\Id()
18
     * @ORM\GeneratedValue()
19
     * @ORM\Column(type="integer")
20
     */
21
    private $id;
22
23
    /**
24
     * @ORM\Column(type="string", length=255)
25
     */
26
    private $slug;
27
28
    /**
29
     * @ORM\Column(type="string", length=255)
30
     */
31
    private $name;
32
33
    /**
34
     * @ORM\OneToMany(targetEntity="App\Entity\Property", mappedBy="area")
35
     */
36
    private $properties;
37
38
    /**
39
     * @ORM\ManyToOne(targetEntity="App\Entity\Locality", inversedBy="areas")
40
     * @ORM\JoinColumn(nullable=false)
41
     */
42
    private $locality;
43
44
    public function __construct()
45
    {
46
        $this->properties = new ArrayCollection();
47
    }
48
49
    public function getId(): ?int
50
    {
51
        return $this->id;
52
    }
53
54
    public function getSlug(): ?string
55
    {
56
        return $this->slug;
57
    }
58
59
    public function setSlug(string $slug): self
60
    {
61
        $this->slug = $slug;
62
63
        return $this;
64
    }
65
66
    public function getName(): ?string
67
    {
68
        return $this->name;
69
    }
70
71
    public function setName(string $name): self
72
    {
73
        $this->name = $name;
74
75
        return $this;
76
    }
77
78
    public function getLocality(): ?Locality
79
    {
80
        return $this->locality;
81
    }
82
83
    public function setLocality(?Locality $locality): self
84
    {
85
        $this->locality = $locality;
86
87
        return $this;
88
    }
89
90
    /**
91
     * @return Collection|Property[]
92
     */
93
    public function getProperties(): Collection
94
    {
95
        return $this->properties;
96
    }
97
98
    public function addProperty(Property $property): self
99
    {
100
        if (!$this->properties->contains($property)) {
101
            $this->properties[] = $property;
102
            $property->setLocality($this);
0 ignored issues
show
Bug introduced by
$this of type App\Entity\Area is incompatible with the type App\Entity\Locality|null expected by parameter $locality of App\Entity\Property::setLocality(). ( Ignorable by Annotation )

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

102
            $property->setLocality(/** @scrutinizer ignore-type */ $this);
Loading history...
103
        }
104
105
        return $this;
106
    }
107
108
    public function removeProperty(Property $property): self
109
    {
110
        if ($this->properties->contains($property)) {
111
            $this->properties->removeElement($property);
112
            // set the owning side to null (unless already changed)
113
            if ($property->getLocality() === $this) {
114
                $property->setLocality(null);
115
            }
116
        }
117
118
        return $this;
119
    }
120
}
121