RepertoireSeason::setPerformances()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 12
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", fetch="EAGER")
44
     */
45
    private $performances;
46
47
    /**
48
     * @JMS\Expose()
49
     */
50
    public $performanceCount;
51
52 1
    public function __construct()
53
    {
54 1
        $this->performances = new ArrayCollection();
55 1
    }
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 1
    public function setStartDate(?\DateTime $startDate): self
68
    {
69 1
        $this->startDate = $startDate;
70
71 1
        return $this;
72
    }
73
74 3
    public function getEndDate(): ?\DateTime
75
    {
76 3
        return $this->endDate;
77
    }
78
79 1
    public function setEndDate(?\DateTime $endDate): self
80
    {
81 1
        $this->endDate = $endDate;
82
83 1
        return $this;
84
    }
85
86 4
    public function getNumber(): ?int
87
    {
88 4
        return $this->number;
89
    }
90
91 1
    public function setNumber(int $number): self
92
    {
93 1
        $this->number = $number;
94
95 1
        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 setPerformances(iterable $performances)
107
    {
108
        if (is_array($performances)) $this->performances = new ArrayCollection($performances);
109
        elseif ($performances instanceof Collection) $this->performances = $performances;
110
        else throw new \InvalidArgumentException('Argument must be array or Collection');
111
    }
112
113
    public function addPerformance(Performance $performance): self
114
    {
115
        if (!$this->performances->contains($performance)) {
116
            $this->performances[] = $performance;
117
            $performance->addSeason($this);
118
        }
119
120
        return $this;
121
    }
122
123
    public function removePerformance(Performance $performance): self
124
    {
125
        if ($this->performances->contains($performance)) {
126
            $this->performances->removeElement($performance);
127
            $performance->removeSeason($this);
128
        }
129
130
        return $this;
131
    }
132
133
    /**
134
     * @JMS\VirtualProperty()
135
     * @JMS\SerializedName("name")
136
     */
137 3
    public function __toString()
138
    {
139 3
        if (!$this->startDate || !$this->endDate) return $this->getNumber();
140 3
        return sprintf(
141 3
            '%s (%s - %s)',
142 3
            $this->getNumber(),
143 3
            $this->getStartDate()->format('Y'),
144 3
            $this->getEndDate()->format('Y')
145
        );
146
    }
147
}
148