Completed
Push — master ( f10175...d8ea43 )
by Jérémy
02:02
created

Pokemon::getNumber()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * (c) Jérémy Marodon <[email protected]>
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Th3Mouk\PokemonGoIVCalculator\Entities;
10
11
use Illuminate\Support\Collection;
12
13
class Pokemon
14
{
15
    /**
16
     * @var int
17
     */
18
    protected $number;
19
20
    /**
21
     * @var string
22
     */
23
    protected $name;
24
25
    /**
26
     * @var int
27
     */
28
    protected $cp;
29
30
    /**
31
     * @var int
32
     */
33
    protected $hp;
34
35
    /**
36
     * @var int
37
     */
38
    protected $baseAttack;
39
40
    /**
41
     * @var int
42
     */
43
    protected $baseDefense;
44
45
    /**
46
     * @var int
47
     */
48
    protected $baseStamina;
49
50
    /**
51
     * @var Collection
52
     */
53
    protected $ivCombinaisons;
54
55
    /**
56
     * Pokemon constructor.
57
     * @param int    $number
58
     * @param string $name
59
     * @param int    $baseAttack
60
     * @param int    $baseDefense
61
     * @param int    $baseStamina
62
     */
63
    public function __construct(
64
        int $number,
65
        string $name,
66
        int $baseAttack,
67
        int $baseDefense,
68
        int $baseStamina
69
    ) {
70
        $this->number = $number;
71
        $this->name = $name;
72
        $this->baseAttack = $baseAttack;
73
        $this->baseDefense = $baseDefense;
74
        $this->baseStamina = $baseStamina;
75
    }
76
77
    /**
78
     * Return the minimum of perfection of a Pokemon
79
     * @return IvCombinaison|null
80
     */
81
    public function getMinimumCombinaison(): ?IvCombinaison
82
    {
83
        return $this->getIvCombinaisons()
84
            ->sortBy(
85
                function (IvCombinaison $combinaison) {
86
                    return $combinaison->getPerfection();
87
                })
88
            ->last();
89
    }
90
91
    /**
92
     * Return the maximum of perfection of a Pokemon
93
     * @return IvCombinaison|null
94
     */
95
    public function getMaximumCombinaison(): ?IvCombinaison
96
    {
97
        return $this->getIvCombinaisons()
98
            ->sortBy(
99
                function (IvCombinaison $combinaison) {
100
                    return $combinaison->getPerfection();
101
                })
102
            ->first();
103
    }
104
105
    /**
106
     * Return the average perfection of a Pokemon
107
     * @return float|null
108
     */
109
    public function getAveragePerfection(): ?float
110
    {
111
        return $this->getIvCombinaisons()->average(
112
            function (IvCombinaison $combinaison) {
113
                return $combinaison->getPerfection();
114
            });
115
    }
116
117
    /**
118
     * Return the min attack of a Pokemon
119
     * @return int
120
     */
121
    public function getMinAttack(): ?int
122
    {
123
        return $this->getIvCombinaisons()->min(
124
            function (IvCombinaison $combinaison) {
125
                return $combinaison->getAttack();
126
            });
127
    }
128
129
    /**
130
     * Return the max attack of a Pokemon
131
     * @return int
132
     */
133
    public function getMaxAttack(): ?int
134
    {
135
        return $this->getIvCombinaisons()->max(
136
            function (IvCombinaison $combinaison) {
137
                return $combinaison->getAttack();
138
            });
139
    }
140
141
    /**
142
     * Return the min defense of a Pokemon
143
     * @return int
144
     */
145
    public function getMinDefense(): ?int
146
    {
147
        return $this->getIvCombinaisons()->min(
148
            function (IvCombinaison $combinaison) {
149
                return $combinaison->getDefense();
150
            });
151
    }
152
153
    /**
154
     * Return the max defense of a Pokemon
155
     * @return int
156
     */
157
    public function getMaxDefense(): ?int
158
    {
159
        return $this->getIvCombinaisons()->max(
160
            function (IvCombinaison $combinaison) {
161
                return $combinaison->getDefense();
162
            });
163
    }
164
165
    /**
166
     * Return the min stamina of a Pokemon
167
     * @return int
168
     */
169
    public function getMinStamina(): ?int
170
    {
171
        return $this->getIvCombinaisons()->min(
172
            function (IvCombinaison $combinaison) {
173
                return $combinaison->getStamina();
174
            });
175
    }
176
177
    /**
178
     * Return the max stamina of a Pokemon
179
     * @return int
180
     */
181
    public function getMaxStamina(): ?int
182
    {
183
        return $this->getIvCombinaisons()->max(
184
            function (IvCombinaison $combinaison) {
185
                return $combinaison->getStamina();
186
            });
187
    }
188
189
    /**
190
     * Get ivCombinaisons
191
     *
192
     * @return Collection
193
     */
194
    public function getIvCombinaisons(): Collection
195
    {
196
        return $this->ivCombinaisons;
197
    }
198
199
    /**
200
     * Set ivCombinaisons
201
     *
202
     * @param Collection $ivCombinaisons
203
     *
204
     * @return Pokemon
205
     */
206
    public function setIvCombinaisons(Collection $ivCombinaisons)
207
    {
208
        $this->ivCombinaisons = $ivCombinaisons;
209
210
        return $this;
211
    }
212
213
    /**
214
     * Get number
215
     *
216
     * @return int
217
     */
218
    public function getNumber(): int
219
    {
220
        return $this->number;
221
    }
222
223
    /**
224
     * Get name
225
     *
226
     * @return string
227
     */
228
    public function getName(): string
229
    {
230
        return $this->name;
231
    }
232
233
    /**
234
     * Get cp
235
     *
236
     * @return int|null
237
     */
238
    public function getCp(): ?int
239
    {
240
        return $this->cp;
241
    }
242
243
    /**
244
     * Set cp
245
     *
246
     * @param int $cp
247
     *
248
     * @return Pokemon
249
     */
250
    public function setCp(int $cp)
251
    {
252
        $this->cp = $cp;
253
        return $this;
254
    }
255
256
    /**
257
     * Get hp
258
     *
259
     * @return int|null
260
     */
261
    public function getHp(): ?int
262
    {
263
        return $this->hp;
264
    }
265
266
    /**
267
     * Set hp
268
     *
269
     * @param int $hp
270
     *
271
     * @return Pokemon
272
     */
273
    public function setHp(int $hp)
274
    {
275
        $this->hp = $hp;
276
        return $this;
277
    }
278
279
    /**
280
     * Get baseAttack
281
     *
282
     * @return int
283
     */
284
    public function getBaseAttack(): int
285
    {
286
        return $this->baseAttack;
287
    }
288
289
    /**
290
     * Get baseDefense
291
     *
292
     * @return int
293
     */
294
    public function getBaseDefense(): int
295
    {
296
        return $this->baseDefense;
297
    }
298
299
    /**
300
     * Get baseStamina
301
     *
302
     * @return int
303
     */
304
    public function getBaseStamina(): int
305
    {
306
        return $this->baseStamina;
307
    }
308
}
309