Completed
Pull Request — master (#168)
by Serhii
02:19
created

RepertoireSeason::addPerformance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace App\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\Common\Collections\Collection;
7
use Doctrine\ORM\Mapping as ORM;
8
use JMS\Serializer\Annotation as JMS;
9
10
/**
11
 * @ORM\Entity(repositoryClass="App\Repository\RepertoireSeasonRepository")
12
 * @JMS\ExclusionPolicy("all")
13
 */
14
class RepertoireSeason
15
{
16
    /**
17
     * @ORM\Id()
18
     * @ORM\GeneratedValue()
19
     * @ORM\Column(type="integer")
20
     * @JMS\Expose()
21
     */
22
    private $id;
23
24
    /**
25
     * @ORM\Column(type="datetime")
26
     * @JMS\Expose()
27
     */
28
    private $startDate;
29
30
    /**
31
     * @ORM\Column(type="datetime")
32
     * @JMS\Expose()
33
     */
34
    private $endDate;
35
36
    /**
37
     * @ORM\Column(type="integer", unique=true)
38
     * @JMS\Expose()
39
     */
40
    private $number;
41
42
    /**
43
     * @ORM\ManyToMany(targetEntity="App\Entity\Performance", mappedBy="seasons")
44
     */
45
    private $performances;
46
47
    /**
48
     * @JMS\Expose()
49
     */
50
    public $performanceCount;
51
52
    public function __construct()
53
    {
54
        $this->performances = new ArrayCollection();
55
    }
56
57
    public function getId(): ?int
58
    {
59
        return $this->id;
60
    }
61
62 3
    public function getStartDate(): ?\DateTime
63
    {
64 3
        return $this->startDate;
65
    }
66
67
    public function setStartDate(?\DateTime $startDate): self
68
    {
69
        $this->startDate = $startDate;
70
71
        return $this;
72
    }
73
74 3
    public function getEndDate(): ?\DateTime
75
    {
76 3
        return $this->endDate;
77
    }
78
79
    public function setEndDate(?\DateTime $endDate): self
80
    {
81
        $this->endDate = $endDate;
82
83
        return $this;
84
    }
85
86 3
    public function getNumber(): ?int
87
    {
88 3
        return $this->number;
89
    }
90
91
    public function setNumber(int $number): self
92
    {
93
        $this->number = $number;
94
95
        return $this;
96
    }
97
98
    /**
99
     * @return Collection|Performance[]
100
     */
101
    public function getPerformances(): Collection
102
    {
103
        return $this->performances;
104
    }
105
106
    public function addPerformance(Performance $performance): self
107
    {
108
        if (!$this->performances->contains($performance)) {
109
            $this->performances[] = $performance;
110
            $performance->addSeason($this);
111
        }
112
113
        return $this;
114
    }
115
116
    public function removePerformance(Performance $performance): self
117
    {
118
        if ($this->performances->contains($performance)) {
119
            $this->performances->removeElement($performance);
120
            $performance->removeSeason($this);
121
        }
122
123
        return $this;
124
    }
125
126
    /**
127
     * @JMS\VirtualProperty()
128
     * @JMS\SerializedName("name")
129
     */
130 3
    public function __toString()
131
    {
132 3
        if (!$this->startDate || !$this->endDate) return $this->getNumber();
133 3
        return sprintf(
134 3
            '%s (%s - %s)',
135 3
            $this->getNumber(),
136 3
            $this->getStartDate()->format('Y'),
137 3
            $this->getEndDate()->format('Y')
138
        );
139
    }
140
}
141