Completed
Push — master ( 617669...1ac4b7 )
by Jérémy
03:27
created

Pokemon::getMaxLevel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
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 string[]
27
     */
28
    protected $types;
29
30
    /**
31
     * @var int
32
     */
33
    protected $cp;
34
35
    /**
36
     * @var int
37
     */
38
    protected $hp;
39
40
    /**
41
     * @var int
42
     */
43
    protected $baseAttack;
44
45
    /**
46
     * @var int
47
     */
48
    protected $baseDefense;
49
50
    /**
51
     * @var int
52
     */
53
    protected $baseStamina;
54
55
    /**
56
     * @var Collection
57
     */
58
    protected $ivCombinaisons;
59
60
    /**
61
     * Pokemon constructor.
62
     * @param int      $number
63
     * @param string   $name
64
     * @param int      $baseAttack
65
     * @param int      $baseDefense
66
     * @param int      $baseStamina
67
     * @param string[] $types
68
     */
69
    public function __construct(
70
        int $number,
71
        string $name,
72
        int $baseAttack,
73
        int $baseDefense,
74
        int $baseStamina,
75
        array $types
76
    ) {
77
        $this->number = $number;
78
        $this->name = $name;
79
        $this->baseAttack = $baseAttack;
80
        $this->baseDefense = $baseDefense;
81
        $this->baseStamina = $baseStamina;
82
        $this->types = $types;
83
    }
84
85
    /**
86
     * Return the minimum of perfection of a Pokemon
87
     * @return IvCombinaison|null
88
     */
89
    public function getMinimumCombinaison(): ?IvCombinaison
90
    {
91
        return $this->getIvCombinaisons()
92
            ->sortBy(
93
                function (IvCombinaison $combinaison) {
94
                    return $combinaison->getPerfection();
95
                })
96
            ->last();
97
    }
98
99
    /**
100
     * Return the maximum of perfection of a Pokemon
101
     * @return IvCombinaison|null
102
     */
103
    public function getMaximumCombinaison(): ?IvCombinaison
104
    {
105
        return $this->getIvCombinaisons()
106
            ->sortBy(
107
                function (IvCombinaison $combinaison) {
108
                    return $combinaison->getPerfection();
109
                })
110
            ->first();
111
    }
112
113
    /**
114
     * Return the average perfection of a Pokemon
115
     * @return float|null
116
     */
117
    public function getAveragePerfection(): ?float
118
    {
119
        return $this->getIvCombinaisons()->average(
120
            function (IvCombinaison $combinaison) {
121
                return $combinaison->getPerfection();
122
            });
123
    }
124
125
    /**
126
     * Return the min attack of a Pokemon
127
     * @return int
128
     */
129
    public function getMinAttack(): ?int
130
    {
131
        return $this->getIvCombinaisons()->min(
132
            function (IvCombinaison $combinaison) {
133
                return $combinaison->getAttack();
134
            });
135
    }
136
137
    /**
138
     * Return the max attack of a Pokemon
139
     * @return int
140
     */
141
    public function getMaxAttack(): ?int
142
    {
143
        return $this->getIvCombinaisons()->max(
144
            function (IvCombinaison $combinaison) {
145
                return $combinaison->getAttack();
146
            });
147
    }
148
149
    /**
150
     * Return the min defense of a Pokemon
151
     * @return int
152
     */
153
    public function getMinDefense(): ?int
154
    {
155
        return $this->getIvCombinaisons()->min(
156
            function (IvCombinaison $combinaison) {
157
                return $combinaison->getDefense();
158
            });
159
    }
160
161
    /**
162
     * Return the max defense of a Pokemon
163
     * @return int
164
     */
165
    public function getMaxDefense(): ?int
166
    {
167
        return $this->getIvCombinaisons()->max(
168
            function (IvCombinaison $combinaison) {
169
                return $combinaison->getDefense();
170
            });
171
    }
172
173
    /**
174
     * Return the min stamina of a Pokemon
175
     * @return int
176
     */
177
    public function getMinStamina(): ?int
178
    {
179
        return $this->getIvCombinaisons()->min(
180
            function (IvCombinaison $combinaison) {
181
                return $combinaison->getStamina();
182
            });
183
    }
184
185
    /**
186
     * Return the max stamina of a Pokemon
187
     * @return int
188
     */
189
    public function getMaxStamina(): ?int
190
    {
191
        return $this->getIvCombinaisons()->max(
192
            function (IvCombinaison $combinaison) {
193
                return $combinaison->getStamina();
194
            });
195
    }
196
197
    /**
198
     * Return the min level of a Pokemon
199
     * @return float
200
     */
201
    public function getMinLevel(): ?float
202
    {
203
        return $this->getIvCombinaisons()
204
            ->map(function (IvCombinaison $combinaison) {
205
                return $combinaison->getLevel()->getLevel();
206
            })
207
            ->sortBy(function ($value) {
208
                return $value;
209
            })
210
            ->first();
211
    }
212
213
    /**
214
     * Return the max level of a Pokemon
215
     * @return float
216
     */
217
    public function getMaxLevel(): ?float
218
    {
219
        return $this->getIvCombinaisons()
220
            ->map(function (IvCombinaison $combinaison) {
221
                return $combinaison->getLevel()->getLevel();
222
            })
223
            ->sortBy(function ($value) {
224
                return $value;
225
            })
226
            ->last();
227
    }
228
229
    /**
230
     * Get ivCombinaisons
231
     *
232
     * @return Collection
233
     */
234
    public function getIvCombinaisons(): Collection
235
    {
236
        return $this->ivCombinaisons;
237
    }
238
239
    /**
240
     * Set ivCombinaisons
241
     *
242
     * @param Collection $ivCombinaisons
243
     *
244
     * @return Pokemon
245
     */
246
    public function setIvCombinaisons(Collection $ivCombinaisons)
247
    {
248
        $this->ivCombinaisons = $ivCombinaisons;
249
250
        return $this;
251
    }
252
253
    /**
254
     * Get number
255
     *
256
     * @return int
257
     */
258
    public function getNumber(): int
259
    {
260
        return $this->number;
261
    }
262
263
    /**
264
     * Get name
265
     *
266
     * @return string
267
     */
268
    public function getName(): string
269
    {
270
        return $this->name;
271
    }
272
273
    /**
274
     * Get types
275
     *
276
     * @return \string[]
277
     */
278
    public function getTypes(): array
279
    {
280
        return $this->types;
281
    }
282
283
    /**
284
     * Get cp
285
     *
286
     * @return int|null
287
     */
288
    public function getCp(): ?int
289
    {
290
        return $this->cp;
291
    }
292
293
    /**
294
     * Set cp
295
     *
296
     * @param int $cp
297
     *
298
     * @return Pokemon
299
     */
300
    public function setCp(int $cp)
301
    {
302
        $this->cp = $cp;
303
        return $this;
304
    }
305
306
    /**
307
     * Get hp
308
     *
309
     * @return int|null
310
     */
311
    public function getHp(): ?int
312
    {
313
        return $this->hp;
314
    }
315
316
    /**
317
     * Set hp
318
     *
319
     * @param int $hp
320
     *
321
     * @return Pokemon
322
     */
323
    public function setHp(int $hp)
324
    {
325
        $this->hp = $hp;
326
        return $this;
327
    }
328
329
    /**
330
     * Get baseAttack
331
     *
332
     * @return int
333
     */
334
    public function getBaseAttack(): int
335
    {
336
        return $this->baseAttack;
337
    }
338
339
    /**
340
     * Get baseDefense
341
     *
342
     * @return int
343
     */
344
    public function getBaseDefense(): int
345
    {
346
        return $this->baseDefense;
347
    }
348
349
    /**
350
     * Get baseStamina
351
     *
352
     * @return int
353
     */
354
    public function getBaseStamina(): int
355
    {
356
        return $this->baseStamina;
357
    }
358
}
359