| 1 | <?php |
||
| 12 | class Fibonacci extends Combinatorics implements \Iterator, \Countable |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * The maximum limit. |
||
| 17 | * |
||
| 18 | * @var int |
||
| 19 | */ |
||
| 20 | protected $max; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * The previous element. |
||
| 24 | * |
||
| 25 | * @var int |
||
| 26 | */ |
||
| 27 | private $previous = 1; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * The current element. |
||
| 31 | * |
||
| 32 | * @var int |
||
| 33 | */ |
||
| 34 | private $current = 0; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * The current key. |
||
| 38 | * |
||
| 39 | * @var int |
||
| 40 | */ |
||
| 41 | private $key = 0; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Fibonacci constructor. |
||
| 45 | */ |
||
| 46 | 2 | public function __construct() |
|
| 50 | |||
| 51 | /** |
||
| 52 | * {@inheritdoc} |
||
| 53 | */ |
||
| 54 | 2 | public function current() |
|
| 58 | |||
| 59 | /** |
||
| 60 | * {@inheritdoc} |
||
| 61 | */ |
||
| 62 | public function key() |
||
| 66 | |||
| 67 | /** |
||
| 68 | * {@inheritdoc} |
||
| 69 | */ |
||
| 70 | 2 | public function next() |
|
| 75 | |||
| 76 | /** |
||
| 77 | * {@inheritdoc} |
||
| 78 | */ |
||
| 79 | 2 | public function rewind() |
|
| 85 | |||
| 86 | /** |
||
| 87 | * {@inheritdoc} |
||
| 88 | */ |
||
| 89 | 2 | public function valid() |
|
| 93 | |||
| 94 | /** |
||
| 95 | * {@inheritdoc} |
||
| 96 | */ |
||
| 97 | 2 | public function count() |
|
| 101 | |||
| 102 | /** |
||
| 103 | * Convert the iterator into an array. |
||
| 104 | * |
||
| 105 | * @return array |
||
| 106 | * The elements. |
||
| 107 | */ |
||
| 108 | 2 | public function toArray() |
|
| 109 | { |
||
| 110 | 2 | $data = array(); |
|
| 111 | |||
| 112 | 2 | for ($this->rewind(); $this->valid(); $this->next()) { |
|
| 113 | 2 | $data[] = $this->current(); |
|
| 114 | } |
||
| 115 | |||
| 116 | 2 | return $data; |
|
| 117 | } |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Set the maximum limit. |
||
| 121 | * |
||
| 122 | * @param int $max |
||
| 123 | * The limit. |
||
| 124 | */ |
||
| 125 | 2 | public function setMaxLimit($max) |
|
| 129 | |||
| 130 | /** |
||
| 131 | * Get the maximum limit. |
||
| 132 | * |
||
| 133 | * @return int |
||
| 134 | * The limit. |
||
| 135 | */ |
||
| 136 | 2 | public function getMaxLimit() |
|
| 140 | } |
||
| 141 |