Fibonacci   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 0
f 0
dl 0
loc 26
ccs 0
cts 10
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 11 2
A generator() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace drupol\phpermutations\Generators;
6
7
use drupol\phpermutations\GeneratorInterface;
8
use drupol\phpermutations\Iterators\Fibonacci as FibonacciIterator;
9
use Generator;
10
11
class Fibonacci extends FibonacciIterator implements GeneratorInterface
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public function generator(): Generator
17
    {
18
        return $this->get();
19
    }
20
21
    /**
22
     * The generator.
23
     *
24
     * @return Generator<int>
25
     */
26
    protected function get(): Generator
27
    {
28
        $a = 0;
29
        $b = 1;
30
        $to = $this->getMaxLimit();
31
32
        while (0 < $to) {
33
            yield $a;
34
35
            [$a, $b] = [$b, $a + $b];
36
            --$to;
37
        }
38
    }
39
}
40