Passed
Push — develop ( 574080...0f5d99 )
by BENARD
04:30
created

Group::addChart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
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 Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\ORM\Mapping as ORM;
10
use Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface;
11
use Gedmo\Timestampable\Traits\TimestampableEntity;
12
use Knp\DoctrineBehaviors\Model\Sluggable\SluggableTrait;
13
use Symfony\Component\Intl\Locale;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Intl\Locale was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Symfony\Component\Validator\Constraints as Assert;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Validator\Constraints was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use VideoGamesRecords\CoreBundle\Model\Entity\NbChartTrait;
16
use VideoGamesRecords\CoreBundle\Model\Entity\NbPlayerTrait;
17
use VideoGamesRecords\CoreBundle\Model\Entity\NbPostTrait;
18
19
/**
20
 * Group
21
 *
22
 * @ORM\Table(
23
 *     name="vgr_group",
24
 *     indexes={
25
 *         @ORM\Index(name="idx_libGroupFr", columns={"libGroupFr"}),
26
 *         @ORM\Index(name="idx_libGroupEn", columns={"libGroupEn"})
27
 *     }
28
 * )
29
 * @ORM\Entity(repositoryClass="VideoGamesRecords\CoreBundle\Repository\GroupRepository")
30
 * @ORM\EntityListeners({"VideoGamesRecords\CoreBundle\EventListener\Entity\GroupListener"})
31
 * @ApiFilter(
32
 *     OrderFilter::class,
33
 *     properties={
34
 *          "id":"ASC",
35
 *          "libGroupEn" : "ASC",
36
 *          "libGroupFr" : "ASC",
37
 *     },
38
 *     arguments={"orderParameterName"="order"}
39
 * )
40
 */
41
class Group implements SluggableInterface
42
{
43
    use TimestampableEntity;
44
    use SluggableTrait;
45
    use NbChartTrait;
46
    use NbPostTrait;
47
    use NbPlayerTrait;
48
49
    /**
50
     * @ORM\Column(name="id", type="integer")
51
     * @ORM\Id
52
     * @ORM\GeneratedValue(strategy="IDENTITY")
53
     */
54
    protected ?int $id = null;
55
56
    /**
57
     * @Assert\Length(max="255")
58
     * @ORM\Column(name="libGroupEn", type="string", length=255, nullable=false)
59
     */
60
    private ?string $libGroupEn;
61
62
    /**
63
     * @Assert\Length(max="255")
64
     * @ORM\Column(name="libGroupFr", type="string", length=255, nullable=false)
65
     */
66
    private ?string $libGroupFr = null;
67
68
    /**
69
     * @ORM\Column(name="boolDlc", type="boolean", nullable=false)
70
     */
71
    private bool $boolDlc = false;
72
73
74
    /**
75
     * @Assert\NotNull
76
     * @ORM\ManyToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Game", inversedBy="groups")
77
     * @ORM\JoinColumns({
78
     *   @ORM\JoinColumn(name="idGame", referencedColumnName="id", nullable=false)
79
     * })
80
     */
81
    private Game $game;
82
83
    /**
84
     * @ORM\OneToMany(targetEntity="VideoGamesRecords\CoreBundle\Entity\Chart", mappedBy="group",cascade={"persist"})
85
     */
86
    private Collection $charts;
87
88
    /**
89
     * Constructor
90
     */
91
    public function __construct()
92
    {
93
        $this->charts = new ArrayCollection();
94
    }
95
96
    /**
97
     * @return string
98
     */
99
    public function __toString()
100
    {
101
        return sprintf('%s [%s]', $this->getDefaultName(), $this->id);
102
    }
103
104
    /**
105
     * @return string
106
     */
107
    public function getDefaultName(): string
108
    {
109
        return $this->libGroupEn;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->libGroupEn could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
110
    }
111
112
    /**
113
     * @return string|null
114
     */
115
    public function getName(): ?string
116
    {
117
        $locale = Locale::getDefault();
118
        if ($locale == 'fr') {
119
            return $this->libGroupFr;
120
        } else {
121
            return $this->libGroupEn;
122
        }
123
    }
124
125
    /**
126
     * Set idGroup
127
     * @param integer $id
128
     * @return $this
129
     */
130
    public function setId(int $id)
131
    {
132
        $this->id = $id;
133
        return $this;
134
    }
135
136
    /**
137
     * Get idGroup
138
     * @return integer
139
     */
140
    public function getId()
141
    {
142
        return $this->id;
143
    }
144
145
    /**
146
     * @param string $libGroupEn
147
     * @return $this
148
     */
149
    public function setLibGroupEn(string $libGroupEn): Group
150
    {
151
        $this->libGroupEn = $libGroupEn;
152
        return $this;
153
    }
154
155
    /**
156
     * @return string
157
     */
158
    public function getLibGroupEn(): ?string
159
    {
160
        return $this->libGroupEn;
161
    }
162
163
    /**
164
     * @param string $libGroupFr
165
     * @return $this
166
     */
167
    public function setLibGroupFr(string $libGroupFr): Group
168
    {
169
        $this->libGroupFr = $libGroupFr;
170
        return $this;
171
    }
172
173
    /**
174
     * @return string
175
     */
176
    public function getLibGroupFr(): ?string
177
    {
178
        return $this->libGroupFr;
179
    }
180
181
    /**
182
     * Set boolDlc
183
     * @param bool $boolDlc
184
     * @return $this
185
     */
186
    public function setBoolDlc(bool $boolDlc): Group
187
    {
188
        $this->boolDlc = $boolDlc;
189
190
        return $this;
191
    }
192
193
    /**
194
     * Get boolDlc
195
     * @return bool
196
     */
197
    public function getBoolDlc(): bool
198
    {
199
        return $this->boolDlc;
200
    }
201
202
203
    /**
204
     * Set Game
205
     * @param Game|null $game
206
     * @return $this
207
     */
208
    public function setGame(Game $game = null): Group
209
    {
210
        $this->game = $game;
211
212
        return $this;
213
    }
214
215
    /**
216
     * Get game
217
     * @return Game
218
     */
219
    public function getGame(): Game
220
    {
221
        return $this->game;
222
    }
223
224
    /**
225
     * @param Chart $chart
226
     * @return $this
227
     */
228
    public function addChart(Chart $chart): Group
229
    {
230
        $this->charts[] = $chart;
231
        return $this;
232
    }
233
234
    /**
235
     * @param Chart $chart
236
     */
237
    public function removeChart(Chart $chart): void
238
    {
239
        $this->charts->removeElement($chart);
240
    }
241
242
    /**
243
     * @return Collection
244
     */
245
    public function getCharts(): Collection
246
    {
247
        return $this->charts;
248
    }
249
250
    /**
251
     * Returns an array of the fields used to generate the slug.
252
     *
253
     * @return string[]
254
     */
255
    public function getSluggableFields(): array
256
    {
257
        return ['defaultName'];
258
    }
259
}
260