Passed
Push — master ( a2fa16...8a4497 )
by Pol
11:27
created

Fibonacci::valid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace drupol\phpermutations\Iterators;
6
7
use drupol\phpermutations\Iterators;
8
9
use const PHP_INT_MAX;
10
11
/**
12
 * Class Fibonacci.
13
 */
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()
89
    {
90
        return $this->getMaxLimit() > $this->current;
91 2
    }
92
}
93