for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace drupol\phpermutations\Iterators;
use drupol\phpermutations\Iterators;
use const PHP_INT_MAX;
class Fibonacci extends Iterators
{
/**
* @var int
*/
protected $current;
* The maximum limit.
*
protected $max;
* The previous element.
private $previous = 1;
* Fibonacci constructor.
public function __construct()
$this->setMaxLimit(PHP_INT_MAX);
parent::__construct();
}
* Get the maximum limit.
* @return int
* The limit
public function getMaxLimit(): int
return (int) $this->max;
* {@inheritdoc}
* @return void
public function next(): void
[$this->current, $this->previous] = [$this->current + $this->previous, $this->current];
++$this->key;
public function rewind(): void
$this->previous = 1;
$this->current = 0;
$this->key = 0;
* Set the maximum limit.
* @param int $max
public function setMaxLimit($max): void
$this->max = $max;
* @return bool
public function valid(): bool
return $this->getMaxLimit() > $this->current;