Passed
Push — develop ( 82edb1...e703b2 )
by BENARD
04:28
created

Badge::getTitle()   C

Complexity

Conditions 14
Paths 14

Size

Total Lines 26
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 26
rs 6.2666
cc 14
nc 14
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A Badge::majValue() 0 11 3

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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