CpuFactory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 69.44 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 6
dl 25
loc 36
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 25 25 5
A make() 0 4 1

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
declare(strict_types = 1);
3
4
namespace Innmind\HomeostasisBundle\Factory\Factor;
5
6
use Innmind\HomeostasisBundle\Exception\LogicException;
7
use Innmind\Homeostasis\{
8
    Sensor\Measure\Weight,
9
    Factor\Cpu
10
};
11
use Innmind\Math\{
12
    Algebra\Number\Number,
13
    Algebra\Integer,
14
    Polynom\Polynom
15
};
16
use Innmind\Server\Status\Server;
17
use Innmind\TimeContinuum\TimeContinuumInterface;
18
19
final class CpuFactory
20
{
21
    private $weight;
22
    private $polynom;
23
24 4 View Code Duplication
    public function __construct(array $config)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
25
    {
26
        if (
27 4
            !isset($config['weight']) ||
28 4
            !isset($config['polynom'])
29
        ) {
30
            throw new LogicException;
31
        }
32
33 4
        $this->weight = new Weight(new Number($config['weight']));
34 4
        $polynom = new Polynom;
35
36 4
        if (isset($config['polynom']['intercept'])) {
37 4
            $polynom = new Polynom(new Number($config['polynom']['intercept']));
38
        }
39
40 4
        foreach ($config['polynom']['degrees'] ?? [] as $degree => $coeff) {
41 4
            $polynom = $polynom->withDegree(
42 4
                new Integer($degree),
43 4
                new Number($coeff)
44
            );
45
        }
46
47 4
        $this->polynom = $polynom;
48 4
    }
49
50 4
    public function make(TimeContinuumInterface $clock, Server $server): Cpu
51
    {
52 4
        return new Cpu($clock, $server, $this->weight, $this->polynom);
53
    }
54
}
55