LogFactory::__construct()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 25
Code Lines 14

Duplication

Lines 25
Ratio 100 %

Code Coverage

Tests 13
CRAP Score 5.009

Importance

Changes 0
Metric Value
dl 25
loc 25
ccs 13
cts 14
cp 0.9286
rs 8.439
c 0
b 0
f 0
cc 5
eloc 14
nc 5
nop 1
crap 5.009
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\Log
10
};
11
use Innmind\Math\{
12
    Algebra\Number\Number,
13
    Algebra\Integer,
14
    Polynom\Polynom
15
};
16
use Innmind\TimeContinuum\TimeContinuumInterface;
17
use Innmind\LogReader\Reader;
18
use Innmind\Filesystem\Adapter;
19
20
final class LogFactory
21
{
22
    private $weight;
23
    private $polynom;
24
25 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...
26
    {
27
        if (
28 4
            !isset($config['weight']) ||
29 4
            !isset($config['polynom'])
30
        ) {
31
            throw new LogicException;
32
        }
33
34 4
        $this->weight = new Weight(new Number($config['weight']));
35 4
        $polynom = new Polynom;
36
37 4
        if (isset($config['polynom']['intercept'])) {
38 4
            $polynom = new Polynom(new Number($config['polynom']['intercept']));
39
        }
40
41 4
        foreach ($config['polynom']['degrees'] ?? [] as $degree => $coeff) {
42 4
            $polynom = $polynom->withDegree(
43 4
                new Integer($degree),
44 4
                new Number($coeff)
45
            );
46
        }
47
48 4
        $this->polynom = $polynom;
49 4
    }
50
51 4
    public function make(
52
        TimeContinuumInterface $clock,
53
        Reader $reader,
54
        Adapter $directory,
55
        callable $watcher,
56
        string $name
57
    ): Log {
58 4
        return new Log(
59 4
            $clock,
60 4
            $reader,
61 4
            $directory,
62 4
            $this->weight,
63 4
            $this->polynom,
64 4
            $watcher,
65 4
            $name
66
        );
67
    }
68
}
69