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

PrimeFactors::get()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 15
Code Lines 8

Duplication

Lines 6
Ratio 40 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 6
loc 15
ccs 0
cts 13
cp 0
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 6
nop 0
crap 20
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\PrimeFactors as PrimeFactorsIterator;
9
10
/**
11
 * Class PrimeFactors.
12
 */
13
class PrimeFactors extends PrimeFactorsIterator implements GeneratorInterface
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function generator()
19
    {
20
        $number = $this->getNumber();
21
22
        for ($i = 2; $number / $i >= $i; ++$i) {
23
            while (0 === $number % $i) {
24
                yield $i;
25
                $number /= $i;
26
            }
27
        }
28
29
        if (1 < $number) {
30
            yield $number;
31
        }
32
    }
33
}
34