IntegerNormalizerBuilder::build()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlecRabbit\Spinner\Core\Builder;
6
7
use AlecRabbit\Spinner\Core\Builder\Contract\IIntegerNormalizerBuilder;
8
use AlecRabbit\Spinner\Core\Contract\IIntegerNormalizer;
9
use AlecRabbit\Spinner\Core\IntegerNormalizer;
0 ignored issues
show
Bug introduced by
The type AlecRabbit\Spinner\Core\IntegerNormalizer 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...
10
use AlecRabbit\Spinner\Exception\LogicException;
11
12
/**
13
 * @psalm-suppress PossiblyNullArgument
14
 */
15
final class IntegerNormalizerBuilder implements IIntegerNormalizerBuilder
16
{
17
    private ?int $divisor = null;
18
    private ?int $min = null;
19
20
    public function build(): IIntegerNormalizer
21
    {
22
        $this->validate();
23
24
        return new IntegerNormalizer(
25
            $this->divisor,
26
            $this->min,
27
        );
28
    }
29
30
    private function validate(): void
31
    {
32
        match (true) {
33
            $this->divisor === null => throw new LogicException('Divisor value is not set.'),
34
            $this->min === null => throw new LogicException('Min value is not set.'),
35
            default => null,
36
        };
37
    }
38
39
    public function withDivisor(int $divisor): IIntegerNormalizerBuilder
40
    {
41
        $clone = clone $this;
42
        $clone->divisor = $divisor;
43
        return $clone;
44
    }
45
46
    public function withMin(int $min): IIntegerNormalizerBuilder
47
    {
48
        $clone = clone $this;
49
        $clone->min = $min;
50
        return $clone;
51
    }
52
}
53