| 1 | <?php |
||
| 12 | class Fibonacci extends Combinatorics implements \Iterator, \Countable { |
||
| 13 | |||
| 14 | /** |
||
| 15 | * The maximum limit. |
||
| 16 | * |
||
| 17 | * @var int |
||
| 18 | */ |
||
| 19 | protected $max; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * The previous element. |
||
| 23 | * |
||
| 24 | * @var int |
||
| 25 | */ |
||
| 26 | private $previous = 1; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * The current element. |
||
| 30 | * |
||
| 31 | * @var int |
||
| 32 | */ |
||
| 33 | private $current = 0; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * The current key. |
||
| 37 | * |
||
| 38 | * @var int |
||
| 39 | */ |
||
| 40 | private $key = 0; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Fibonacci constructor. |
||
| 44 | */ |
||
| 45 | 2 | public function __construct() { |
|
| 48 | |||
| 49 | /** |
||
| 50 | * {@inheritdoc} |
||
| 51 | */ |
||
| 52 | 2 | public function current() { |
|
| 55 | |||
| 56 | /** |
||
| 57 | * {@inheritdoc} |
||
| 58 | */ |
||
| 59 | public function key() { |
||
| 62 | |||
| 63 | /** |
||
| 64 | * {@inheritdoc} |
||
| 65 | */ |
||
| 66 | 2 | public function next() { |
|
| 70 | |||
| 71 | /** |
||
| 72 | * {@inheritdoc} |
||
| 73 | */ |
||
| 74 | 2 | public function rewind() { |
|
| 79 | |||
| 80 | /** |
||
| 81 | * {@inheritdoc} |
||
| 82 | */ |
||
| 83 | 2 | public function valid() { |
|
| 86 | |||
| 87 | /** |
||
| 88 | * {@inheritdoc} |
||
| 89 | */ |
||
| 90 | 2 | public function count() { |
|
| 93 | |||
| 94 | /** |
||
| 95 | * Convert the iterator into an array. |
||
| 96 | * |
||
| 97 | * @return array |
||
| 98 | * The elements. |
||
| 99 | */ |
||
| 100 | 2 | public function toArray() { |
|
| 101 | 2 | $data = array(); |
|
| 102 | |||
| 103 | 2 | for ($this->rewind(); $this->valid(); $this->next()) { |
|
| 104 | 2 | $data[] = $this->current(); |
|
| 105 | } |
||
| 106 | |||
| 107 | 2 | return $data; |
|
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Set the maximum limit. |
||
| 112 | * |
||
| 113 | * @param int $max |
||
| 114 | * The limit. |
||
| 115 | */ |
||
| 116 | 2 | public function setMaxLimit($max) { |
|
| 119 | |||
| 120 | /** |
||
| 121 | * Get the maximum limit. |
||
| 122 | * |
||
| 123 | * @return int |
||
| 124 | * The limit. |
||
| 125 | */ |
||
| 126 | 2 | public function getMaxLimit() { |
|
| 129 | |||
| 130 | } |
||
| 131 |