| Total Complexity | 6 |
| Total Lines | 77 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | class Fibonacci extends Iterators |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var int |
||
| 18 | */ |
||
| 19 | protected $current; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * The maximum limit. |
||
| 23 | * |
||
| 24 | * @var int |
||
| 25 | */ |
||
| 26 | protected $max; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * The previous element. |
||
| 30 | * |
||
| 31 | * @var int |
||
| 32 | */ |
||
| 33 | private $previous = 1; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Fibonacci constructor. |
||
| 37 | */ |
||
| 38 | public function __construct() |
||
| 39 | { |
||
| 40 | $this->setMaxLimit(PHP_INT_MAX); |
||
| 41 | parent::__construct(); |
||
| 42 | } |
||
| 43 | |||
| 44 | 2 | /** |
|
| 45 | * Get the maximum limit. |
||
| 46 | 2 | * |
|
| 47 | 2 | * @return int |
|
| 48 | 2 | * The limit |
|
| 49 | */ |
||
| 50 | public function getMaxLimit() |
||
| 51 | { |
||
| 52 | return (int) $this->max; |
||
| 53 | 2 | } |
|
| 54 | |||
| 55 | 2 | /** |
|
| 56 | * {@inheritdoc} |
||
| 57 | */ |
||
| 58 | public function next() |
||
| 59 | { |
||
| 60 | [$this->current, $this->previous] = [$this->current + $this->previous, $this->current]; |
||
| 61 | 2 | ++$this->key; |
|
| 62 | } |
||
| 63 | 2 | ||
| 64 | 2 | /** |
|
| 65 | 2 | * {@inheritdoc} |
|
| 66 | */ |
||
| 67 | public function rewind() |
||
| 68 | { |
||
| 69 | $this->previous = 1; |
||
| 70 | 2 | $this->current = 0; |
|
| 71 | $this->key = 0; |
||
| 72 | 2 | } |
|
| 73 | 2 | ||
| 74 | 2 | /** |
|
| 75 | 2 | * Set the maximum limit. |
|
| 76 | * |
||
| 77 | * @param int $max |
||
| 78 | * The limit |
||
| 79 | */ |
||
| 80 | 2 | public function setMaxLimit($max) |
|
| 81 | { |
||
| 82 | 2 | $this->max = $max; |
|
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * {@inheritdoc} |
||
| 87 | */ |
||
| 88 | public function valid() |
||
| 91 | 2 | } |
|
| 92 | } |
||
| 93 |