District::setCity()   A
last analyzed

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
cc 1
eloc 2
c 1
b 0
f 1
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 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\DistrictRepository")
16
 * @UniqueEntity("slug")
17
 */
18
class District
19
{
20
    use EntityIdTrait;
21
    use EntityNameTrait;
22
23
    /**
24
     * @ORM\OneToMany(targetEntity="App\Entity\Property", mappedBy="district")
25
     */
26
    private $properties;
27
28
    /**
29
     * @ORM\ManyToOne(targetEntity="App\Entity\City", inversedBy="districts")
30
     * @ORM\JoinColumn(nullable=false)
31
     */
32
    private $city;
33
34
    public function __construct()
35
    {
36
        $this->properties = new ArrayCollection();
37
    }
38
39
    public function getProperties(): Collection
40
    {
41
        return $this->properties;
42
    }
43
44
    public function addProperty(Property $property): self
45
    {
46
        if (!$this->properties->contains($property)) {
47
            $this->properties[] = $property;
48
            $property->setDistrict($this);
49
        }
50
51
        return $this;
52
    }
53
54
    public function removeProperty(Property $property): self
55
    {
56
        if ($this->properties->contains($property)) {
57
            $this->properties->removeElement($property);
58
            // set the owning side to null (unless already changed)
59
            if ($property->getDistrict() === $this) {
60
                $property->setDistrict(null);
61
            }
62
        }
63
64
        return $this;
65
    }
66
67
    public function getCity(): ?City
68
    {
69
        return $this->city;
70
    }
71
72
    public function setCity(?City $city): self
73
    {
74
        $this->city = $city;
75
76
        return $this;
77
    }
78
}
79