1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Smoren\Sequence\Structs; |
||
6 | |||
7 | /** |
||
8 | * @template T of int|float |
||
9 | * @extends StepSequence<T> |
||
10 | */ |
||
11 | class Range extends StepSequence |
||
12 | { |
||
13 | /** |
||
14 | * @param T $start |
||
15 | * @param int<0, max>|null $size |
||
16 | * @param T $step |
||
17 | */ |
||
18 | 49 | public function __construct($start, ?int $size, $step) |
|
19 | { |
||
20 | 49 | parent::__construct($start, $size, $step); |
|
21 | } |
||
22 | |||
23 | /** |
||
24 | * @param int $index |
||
25 | * @return T |
||
26 | */ |
||
27 | 33 | public function getValueByIndex(int $index) |
|
28 | { |
||
29 | 33 | return $this->start + $index * $this->step; |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
30 | } |
||
31 | |||
32 | /** |
||
33 | * @param T $previousValue |
||
34 | * @return T |
||
35 | */ |
||
36 | 22 | public function getNextValue($previousValue) |
|
37 | { |
||
38 | 22 | return $previousValue + $this->step; |
|
39 | } |
||
40 | } |
||
41 |