CpuFactory::make()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 1
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