1 | <?php |
||
11 | class Fibonacci extends Combinatorics implements IteratorInterface |
||
12 | { |
||
13 | /** |
||
14 | * The maximum limit. |
||
15 | * |
||
16 | * @var int |
||
17 | */ |
||
18 | protected $max; |
||
19 | |||
20 | /** |
||
21 | * The previous element. |
||
22 | * |
||
23 | * @var int |
||
24 | */ |
||
25 | private $previous = 1; |
||
26 | |||
27 | /** |
||
28 | * The current element. |
||
29 | * |
||
30 | * @var int |
||
31 | */ |
||
32 | private $current = 0; |
||
33 | |||
34 | /** |
||
35 | * The current key. |
||
36 | * |
||
37 | * @var int |
||
38 | */ |
||
39 | private $key = 0; |
||
40 | |||
41 | /** |
||
42 | * Fibonacci constructor. |
||
43 | */ |
||
44 | 2 | public function __construct() |
|
45 | { |
||
46 | 2 | $this->setMaxLimit(PHP_INT_MAX); |
|
47 | 2 | parent::__construct([], null); |
|
48 | 2 | } |
|
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | 2 | public function current() |
|
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | 2 | public function next() |
|
66 | |||
67 | /** |
||
68 | * {@inheritdoc} |
||
69 | */ |
||
70 | 2 | public function rewind() |
|
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | 2 | public function valid() |
|
84 | |||
85 | /** |
||
86 | * Set the maximum limit. |
||
87 | * |
||
88 | * @param int $max |
||
89 | * The limit |
||
90 | */ |
||
91 | 2 | public function setMaxLimit($max) |
|
95 | |||
96 | /** |
||
97 | * Get the maximum limit. |
||
98 | * |
||
99 | * @return int |
||
100 | * The limit |
||
101 | */ |
||
102 | 2 | public function getMaxLimit() |
|
106 | } |
||
107 |