PrimeFactors::generator()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

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