Fibonacci   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 14
c 1
b 0
f 0
dl 0
loc 83
ccs 20
cts 20
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A valid() 0 3 1
A next() 0 4 1
A getMaxLimit() 0 3 1
A rewind() 0 5 1
A __construct() 0 4 1
A setMaxLimit() 0 3 1
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
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
92
    {
93 1
        return $this->getMaxLimit() > $this->current;
94
    }
95
}
96