LogFactory::make()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 15
nc 1
nop 5
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\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