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