IntervalNormalizerFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
c 0
b 0
f 0
dl 0
loc 34
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A buildIntegerNormalizer() 0 8 1
A __construct() 0 4 1
A getDivisor() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlecRabbit\Spinner\Core\Factory;
6
7
use AlecRabbit\Spinner\Contract\Mode\NormalizerMode;
8
use AlecRabbit\Spinner\Core\Builder\Contract\IIntegerNormalizerBuilder;
9
use AlecRabbit\Spinner\Core\Contract\IIntegerNormalizer;
10
use AlecRabbit\Spinner\Core\Contract\IIntervalNormalizer;
11
use AlecRabbit\Spinner\Core\Factory\Contract\IIntervalNormalizerFactory;
12
use AlecRabbit\Spinner\Core\IntervalNormalizer;
0 ignored issues
show
Bug introduced by
The type AlecRabbit\Spinner\Core\IntervalNormalizer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
14
final class IntervalNormalizerFactory implements IIntervalNormalizerFactory
15
{
16
    public function __construct(
17
        protected IIntegerNormalizerBuilder $integerNormalizerBuilder,
18
        protected NormalizerMode $normalizerMode,
19
    ) {
20
    }
21
22
    public function create(): IIntervalNormalizer
23
    {
24
        return new IntervalNormalizer(
25
            $this->buildIntegerNormalizer(),
26
        );
27
    }
28
29
    private function buildIntegerNormalizer(): IIntegerNormalizer
30
    {
31
        $divisor = $this->getDivisor();
32
33
        return $this->integerNormalizerBuilder
34
            ->withDivisor($divisor)
35
            ->withMin($divisor)
36
            ->build()
37
        ;
38
    }
39
40
    private function getDivisor(): int
41
    {
42
        return match ($this->normalizerMode) {
43
            NormalizerMode::SMOOTH => 40,
44
            NormalizerMode::BALANCED => 100,
45
            NormalizerMode::PERFORMANCE => 200,
46
            NormalizerMode::SLOW => 1000,
47
            NormalizerMode::STILL => 900000,
48
        };
49
    }
50
}
51