Passed
Push — develop ( a1dd18...3f55cc )
by BENARD
04:37
created

Badge::setTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
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\ApiResource;
6
use Doctrine\ORM\Mapping as ORM;
7
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...
8
use VideoGamesRecords\CoreBundle\Contracts\BadgeInterface;
9
use VideoGamesRecords\CoreBundle\Model\Entity\NbPlayerTrait;
10
11
/**
12
 * Badge
13
 * @ORM\Table(
14
 *     name="vgr_badge",
15
 *     indexes={
16
 *         @ORM\Index(name="idx_type", columns={"type"}),
17
 *         @ORM\Index(name="idx_value", columns={"value"})
18
 *     }
19
 * )
20
 * @ORM\Entity(repositoryClass="VideoGamesRecords\CoreBundle\Repository\BadgeRepository")
21
 * @ApiResource(attributes={"order"={"type", "value"}})
22
 */
23
class Badge implements BadgeInterface
24
{
25
    use NbPlayerTrait;
26
27
    /**
28
     * @ORM\Column(name="id", type="integer")
29
     * @ORM\Id
30
     * @ORM\GeneratedValue(strategy="IDENTITY")
31
     */
32
    private ?int $id = null;
33
34
    /**
35
     * @Assert\Length(max="50")
36
     * @ORM\Column(name="type", type="string", length=50, nullable=false)
37
     */
38
    private string $type;
39
40
    /**
41
     * @Assert\Length(max="100")
42
     * @ORM\Column(name="picture", type="string", length=100, nullable=false, options={"default" : "default.gif"})
43
     */
44
    private string $picture;
45
46
    /**
47
     * @ORM\Column(name="value", type="integer", nullable=false, options={"default":0})
48
     */
49
    private int $value = 0;
50
51
    /**
52
     * @ORM\OneToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Game", mappedBy="badge")
53
     */
54
    private ?Game $game;
55
56
    /**
57
     * @ORM\OneToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Serie", mappedBy="badge")
58
     */
59
    private ?Serie $serie;
60
61
    /**
62
     * @ORM\OneToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Country", mappedBy="badge")
63
     */
64
    private ?Country $country;
65
66
    /**
67
     * @ORM\OneToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Platform", mappedBy="badge")
68
     */
69
    private ?Platform $platform;
70
71
    private string $title = '';
72
73
    /**
74
     * @return string
75
     */
76
    public function __toString()
77
    {
78
        return sprintf('%s / %s [%s]', $this->getType(), $this->getPicture(), $this->getId());
79
    }
80
81
82
    /**
83
     * Set id
84
     * @param integer $id
85
     * @return Badge
86
     */
87
    public function setId(int $id): Badge
88
    {
89
        $this->id = $id;
90
        return $this;
91
    }
92
93
    /**
94
     * Get id
95
     * @return integer
96
     */
97
    public function getId(): ?int
98
    {
99
        return $this->id;
100
    }
101
102
    /**
103
     * Set type
104
     * @param string $type
105
     * @return Badge
106
     */
107
    public function setType(string $type): Badge
108
    {
109
        $this->type = $type;
110
111
        return $this;
112
    }
113
114
    /**
115
     * Get type
116
     * @return string
117
     */
118
    public function getType(): string
119
    {
120
        return $this->type;
121
    }
122
123
124
    /**
125
     * Set picture
126
     * @param string $picture
127
     * @return Badge
128
     */
129
    public function setPicture(string $picture): Badge
130
    {
131
        $this->picture = $picture;
132
133
        return $this;
134
    }
135
136
    /**
137
     * Get picture
138
     * @return string|null
139
     */
140
    public function getPicture(): ?string
141
    {
142
        return $this->picture;
143
    }
144
145
    /**
146
     * Set value
147
     * @param integer $value
148
     * @return Badge
149
     */
150
    public function setValue(int $value): Badge
151
    {
152
        $this->value = $value;
153
154
        return $this;
155
    }
156
157
    /**
158
     * Get value
159
     * @return int
160
     */
161
    public function getValue(): int
162
    {
163
        return $this->value;
164
    }
165
166
    /**
167
     * Get game
168
     * @return Game|null
169
     */
170
    public function getGame(): ?Game
171
    {
172
        return $this->game;
173
    }
174
175
    /**
176
     * @return Serie|null
177
     */
178
    public function getSerie(): ?Serie
179
    {
180
        return $this->serie;
181
    }
182
183
    /**
184
     * Get country
185
     * @return Country|null
186
     */
187
    public function getCountry(): ?Country
188
    {
189
        return $this->country;
190
    }
191
192
    /**
193
     * Get platform
194
     * @return Platform|null
195
     */
196
    public function getPlatform(): ?Platform
197
    {
198
        return $this->platform;
199
    }
200
201
    public function setTitle(string $title): static
202
    {
203
        $this->title = $title;
204
        return $this;
205
    }
206
207
    /**
208
     * @return string
209
     */
210
    public function getTitle(): string
211
    {
212
        return $this->title;
213
    }
214
215
216
    /**
217
     * @return array
218
     */
219
    public static function getTypeChoices(): array
220
    {
221
        return [
222
            self::TYPE_CONNEXION                => self::TYPE_CONNEXION,
223
            self::TYPE_DON                      => self::TYPE_DON,
224
            self::TYPE_FORUM                    => self::TYPE_FORUM,
225
            self::TYPE_INSCRIPTION              => self::TYPE_INSCRIPTION,
226
            self::TYPE_MASTER                   => self::TYPE_MASTER,
227
            self::TYPE_PLATFORM                 => self::TYPE_PLATFORM,
228
            self::TYPE_SERIE                    => self::TYPE_SERIE,
229
            self::TYPE_SPECIAL_WEBMASTER        => self::TYPE_SPECIAL_WEBMASTER,
230
            self::TYPE_TWITCH                   => self::TYPE_TWITCH,
231
            self::TYPE_VGR_CHART                => self::TYPE_VGR_CHART,
232
            self::TYPE_VGR_PROOF                => self::TYPE_VGR_PROOF,
233
            self::TYPE_VGR_SPECIAL_COUNTRY      => self::TYPE_VGR_SPECIAL_COUNTRY,
234
            self::TYPE_VGR_SPECIAL_CUP          => self::TYPE_VGR_SPECIAL_CUP,
235
            self::TYPE_VGR_SPECIAL_LEGEND       => self::TYPE_VGR_SPECIAL_LEGEND,
236
            self::TYPE_VGR_SPECIAL_MEDALS       => self::TYPE_VGR_SPECIAL_MEDALS,
237
            self::TYPE_VGR_SPECIAL_POINTS       => self::TYPE_VGR_SPECIAL_POINTS,
238
        ];
239
    }
240
241
    public function majValue(): void
242
    {
243
        if (self::TYPE_MASTER !== $this->type) {
244
            return;
245
        }
246
        if (0 === $this->nbPlayer) {
247
            $this->value = 0;
248
        } else {
249
            $this->value = floor(
250
                100 * (6250 * (-1 / (100 + $this->getGame()
251
                                ->getNbPlayer() - $this->nbPlayer) + 0.0102) / (pow($this->nbPlayer, 1 / 3)))
252
            );
253
        }
254
    }
255
256
    /**
257
     * @return bool
258
     */
259
    public function isTypeMaster(): bool
260
    {
261
        return $this->type === self::TYPE_MASTER;
262
    }
263
}
264