Passed
Push — develop ( 0abebc...5f8ba8 )
by BENARD
05:36
created

Serie::getDefaultDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace VideoGamesRecords\CoreBundle\Entity;
4
5
use ApiPlatform\Core\Annotation\ApiFilter;
6
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
7
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
8
use Doctrine\Common\Collections\ArrayCollection;
9
use Doctrine\ORM\Mapping as ORM;
10
use Doctrine\Common\Collections\Collection;
11
use Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface;
12
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
13
use Knp\DoctrineBehaviors\Model\Sluggable\SluggableTrait;
14
use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
15
use Gedmo\Timestampable\Traits\TimestampableEntity;
16
use Symfony\Component\Validator\Constraints as Assert;
17
use VideoGamesRecords\CoreBundle\Traits\Entity\NbChartTrait;
18
use VideoGamesRecords\CoreBundle\Traits\Entity\NbGameTrait;
19
use VideoGamesRecords\CoreBundle\Traits\Entity\PictureTrait;
20
use VideoGamesRecords\CoreBundle\ValueObject\SerieStatus;
21
22
/**
23
 * Serie
24
 * @ORM\Table(name="vgr_serie")
25
 * @ORM\Entity(repositoryClass="VideoGamesRecords\CoreBundle\Repository\SerieRepository")
26
 * @ORM\EntityListeners({"VideoGamesRecords\CoreBundle\EventListener\Entity\SerieListener"})
27
 * @ApiFilter(
28
 *     SearchFilter::class,
29
 *     properties={
30
 *          "status": "exact",
31
 *          "libSerie" : "partial",
32
 *      }
33
 * )
34
 * @ApiFilter(
35
 *     OrderFilter::class,
36
 *     properties={
37
 *          "libSerie" : "ASC",
38
 *     },
39
 *     arguments={"orderParameterName"="order"}
40
 * )
41
 */
42
class Serie implements SluggableInterface,TranslatableInterface
43
{
44
    use TimestampableEntity;
45
    use TranslatableTrait;
46
    use SluggableTrait;
47
    use NbChartTrait;
48
    use NbGameTrait;
49
    use PictureTrait;
50
51
    /**
52
     * @ORM\Column(name="id", type="integer")
53
     * @ORM\Id
54
     * @ORM\GeneratedValue(strategy="IDENTITY")
55
     */
56
    private ?int $id = null;
57
58
    /**
59
     * @var string
60
     * @Assert\Length(max="255")
61
     * @ORM\Column(name="libSerie", type="string", length=255, nullable=false)
62
     */
63
    private string $libSerie;
64
65
    /**
66
     * @ORM\Column(name="status", type="string", nullable=false)
67
     */
68
    private string $status = SerieStatus::STATUS_INACTIVE;
69
70
    /**
71
     * @var Collection<Game>
72
     * @ORM\OneToMany(targetEntity="VideoGamesRecords\CoreBundle\Entity\Game", mappedBy="serie", cascade={"persist", "remove"}, orphanRemoval=true)
73
     */
74
    private Collection $games;
75
76
    /**
77
     * @ORM\OneToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Badge", inversedBy="serie", cascade={"persist"}))
78
     * @ORM\JoinColumns({
79
     *   @ORM\JoinColumn(name="idBadge", referencedColumnName="id", nullable=true, onDelete="SET NULL")
80
     * })
81
     */
82
    private ?Badge $badge;
83
84
    /**
85
     * Constructor
86
     */
87
    public function __construct()
88
    {
89
        $this->games = new ArrayCollection();
90
    }
91
92
    /**
93
     * @return string
94
     */
95
    public function __toString(): string
96
    {
97
        return sprintf('%s [%s]', $this->getDefaultName(), $this->id);
98
    }
99
100
    /**
101
     * @return string
102
     */
103
    public function getDefaultName(): string
104
    {
105
        return $this->libSerie;
106
    }
107
108
    /**
109
     * @return string
110
     */
111
    public function getName(): string
112
    {
113
        return $this->libSerie;
114
    }
115
116
    /**
117
     * @param string $libSerie
118
     * @return $this
119
     */
120
    public function setLibSerie(string $libSerie): Serie
121
    {
122
        $this->libSerie = $libSerie;
123
        return $this;
124
    }
125
126
    /**
127
     * @return string
128
     */
129
    public function getLibSerie(): string
130
    {
131
        return $this->libSerie;
132
    }
133
134
    /**
135
     * Set id
136
     * @param integer $id
137
     * @return $this
138
     */
139
    public function setId(int $id): Serie
140
    {
141
        $this->id = $id;
142
        return $this;
143
    }
144
145
    /**
146
     * Get id
147
     * @return int|null
148
     */
149
    public function getId(): ?int
150
    {
151
        return $this->id;
152
    }
153
154
    /**
155
     * Set status
156
     * @param string $status
157
     * @return $this
158
     */
159
    public function setStatus(string $status): Serie
160
    {
161
        $this->status = $status;
162
163
        return $this;
164
    }
165
166
    /**
167
     * Get status
168
     *
169
     * @return SerieStatus
170
     */
171
    public function getStatus(): SerieStatus
172
    {
173
        return new SerieStatus($this->status);
174
    }
175
176
    /**
177
     * @return mixed
178
     */
179
    public function getGames()
180
    {
181
        return $this->games;
182
    }
183
184
    /**
185
     * @param $badge
186
     */
187
    public function setBadge($badge = null): void
188
    {
189
        $this->badge = $badge;
190
    }
191
192
    /**
193
     * Get idBadge
194
     * @return Badge|null
195
     */
196
    public function getBadge(): ?Badge
197
    {
198
        return $this->badge;
199
    }
200
201
    /**
202
     * @param string $description
203
     * @return $this
204
     */
205
    public function setDescription(string $description): Serie
206
    {
207
        $this->translate(null, false)->setDescription($description);
0 ignored issues
show
Bug introduced by
The method setDescription() does not exist on Knp\DoctrineBehaviors\Co...ty\TranslationInterface. It seems like you code against a sub-type of Knp\DoctrineBehaviors\Co...ty\TranslationInterface such as VideoGamesRecords\CoreBu...Entity\SerieTranslation. ( Ignorable by Annotation )

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

207
        $this->translate(null, false)->/** @scrutinizer ignore-call */ setDescription($description);
Loading history...
208
209
        return $this;
210
    }
211
212
    /**
213
     * @return string|null
214
     */
215
    public function getDescription(): ?string
216
    {
217
        return $this->translate(null, false)->getDescription();
0 ignored issues
show
Bug introduced by
The method getDescription() does not exist on Knp\DoctrineBehaviors\Co...ty\TranslationInterface. It seems like you code against a sub-type of Knp\DoctrineBehaviors\Co...ty\TranslationInterface such as VideoGamesRecords\CoreBu...Entity\SerieTranslation. ( Ignorable by Annotation )

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

217
        return $this->translate(null, false)->/** @scrutinizer ignore-call */ getDescription();
Loading history...
218
    }
219
220
    /**
221
     * @return string
222
     */
223
    public function getDefaultDescription(): string
224
    {
225
        return $this->translate('en', false)->getDescription();
226
    }
227
228
    /**
229
     * Returns an array of the fields used to generate the slug.
230
     * @return string[]
231
     */
232
    public function getSluggableFields(): array
233
    {
234
        return ['defaultName'];
235
    }
236
}
237