Passed
Push — develop ( d64e19...d2a67e )
by BENARD
04:33
created

Badge::getSerie()   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\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
    /**
72
     * @return string
73
     */
74
    public function __toString()
75
    {
76
        return sprintf('%s / %s [%s]', $this->getType(), $this->getPicture(), $this->getId());
77
    }
78
79
80
    /**
81
     * Set id
82
     * @param integer $id
83
     * @return Badge
84
     */
85
    public function setId(int $id): Badge
86
    {
87
        $this->id = $id;
88
        return $this;
89
    }
90
91
    /**
92
     * Get id
93
     * @return integer
94
     */
95
    public function getId(): ?int
96
    {
97
        return $this->id;
98
    }
99
100
    /**
101
     * Set type
102
     * @param string $type
103
     * @return Badge
104
     */
105
    public function setType(string $type): Badge
106
    {
107
        $this->type = $type;
108
109
        return $this;
110
    }
111
112
    /**
113
     * Get type
114
     * @return string
115
     */
116
    public function getType(): string
117
    {
118
        return $this->type;
119
    }
120
121
122
    /**
123
     * Set picture
124
     * @param string $picture
125
     * @return Badge
126
     */
127
    public function setPicture(string $picture): Badge
128
    {
129
        $this->picture = $picture;
130
131
        return $this;
132
    }
133
134
    /**
135
     * Get picture
136
     * @return string|null
137
     */
138
    public function getPicture(): ?string
139
    {
140
        return $this->picture;
141
    }
142
143
    /**
144
     * Set value
145
     * @param integer $value
146
     * @return Badge
147
     */
148
    public function setValue(int $value): Badge
149
    {
150
        $this->value = $value;
151
152
        return $this;
153
    }
154
155
    /**
156
     * Get value
157
     * @return int
158
     */
159
    public function getValue(): int
160
    {
161
        return $this->value;
162
    }
163
164
    /**
165
     * Get game
166
     * @return Game|null
167
     */
168
    public function getGame(): ?Game
169
    {
170
        return $this->game;
171
    }
172
173
    /**
174
     * @return Serie|null
175
     */
176
    public function getSerie(): ?Serie
177
    {
178
        return $this->serie;
179
    }
180
181
    /**
182
     * Get country
183
     * @return Country|null
184
     */
185
    public function getCountry(): ?Country
186
    {
187
        return $this->country;
188
    }
189
190
    /**
191
     * Get platform
192
     * @return Platform|null
193
     */
194
    public function getPlatform(): ?Platform
195
    {
196
        return $this->platform;
197
    }
198
199
200
    /**
201
     * @return array
202
     */
203
    public static function getTypeChoices(): array
204
    {
205
        return [
206
            self::TYPE_CONNEXION                => self::TYPE_CONNEXION,
207
            self::TYPE_DON                      => self::TYPE_DON,
208
            self::TYPE_FORUM                    => self::TYPE_FORUM,
209
            self::TYPE_INSCRIPTION              => self::TYPE_INSCRIPTION,
210
            self::TYPE_MASTER                   => self::TYPE_MASTER,
211
            self::TYPE_PLATFORM                 => self::TYPE_PLATFORM,
212
            self::TYPE_SERIE                    => self::TYPE_SERIE,
213
            self::TYPE_SPECIAL_WEBMASTER        => self::TYPE_SPECIAL_WEBMASTER,
214
            self::TYPE_TWITCH                   => self::TYPE_TWITCH,
215
            self::TYPE_VGR_CHART                => self::TYPE_VGR_CHART,
216
            self::TYPE_VGR_PROOF                => self::TYPE_VGR_PROOF,
217
            self::TYPE_VGR_SPECIAL_COUNTRY      => self::TYPE_VGR_SPECIAL_COUNTRY,
218
            self::TYPE_VGR_SPECIAL_CUP          => self::TYPE_VGR_SPECIAL_CUP,
219
            self::TYPE_VGR_SPECIAL_LEGEND       => self::TYPE_VGR_SPECIAL_LEGEND,
220
            self::TYPE_VGR_SPECIAL_MEDALS       => self::TYPE_VGR_SPECIAL_MEDALS,
221
            self::TYPE_VGR_SPECIAL_POINTS       => self::TYPE_VGR_SPECIAL_POINTS,
222
        ];
223
    }
224
225
    public function majValue(): void
226
    {
227
        if (self::TYPE_MASTER !== $this->type) {
228
            return;
229
        }
230
        if (0 === $this->nbPlayer) {
231
            $this->value = 0;
232
        } else {
233
            $this->value = floor(
234
                100 * (6250 * (-1 / (100 + $this->getGame()
235
                                ->getNbPlayer() - $this->nbPlayer) + 0.0102) / (pow($this->nbPlayer, 1 / 3)))
236
            );
237
        }
238
    }
239
240
    /**
241
     * @return bool
242
     */
243
    public function isTypeMaster(): bool
244
    {
245
        return $this->type === self::TYPE_MASTER;
246
    }
247
}
248