Completed
Push — master ( 0b4795...d0bddc )
by Pol
02:26
created

PrimeFactors   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 16.67 %

Coupling/Cohesion

Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
cbo 1
dl 6
loc 36
ccs 0
cts 15
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generator() 0 3 1
A get() 6 14 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace drupol\phpermutations\Generators;
4
5
use drupol\phpermutations\Iterators\PrimeFactors as PrimeFactorsIterator;
6
7
/**
8
 * Class PrimeFactors.
9
 *
10
 * @package drupol\phpermutations\Generators
11
 */
12
class PrimeFactors extends PrimeFactorsIterator {
13
14
  /**
15
   * Alias of the get() method.
16
   *
17
   * @return \Generator
18
   *   The prime factors generator.
19
   */
20
  public function generator() {
21
    return $this->get();
22
  }
23
24
  /**
25
   * The generator.
26
   *
27
   * @codingStandardsIgnoreStart
28
   * @return \Generator
29
   *   The prime factors generator.
30
   * @codingStandardsIgnoreEnd
31
   */
32
  protected function get() {
33
    $number = $this->getNumber();
34
35 View Code Duplication
    for ($i = 2; $i <= $number / $i; $i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
      while ($number % $i == 0) {
37
        yield $i;
38
        $number /= $i;
39
      }
40
    }
41
42
    if ($number > 1) {
43
      yield $number;
44
    }
45
  }
46
47
}
48