Passed
Push — master ( de3d61...be839c )
by Alec
13:42 queued 13s
created

IntegerNormalizerBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
c 0
b 0
f 0
dl 0
loc 36
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A withDivisor() 0 5 1
A validate() 0 6 1
A withMin() 0 5 1
A build() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
6
namespace AlecRabbit\Spinner\Core\Builder;
7
8
use AlecRabbit\Spinner\Core\Builder\Contract\IIntegerNormalizerBuilder;
9
use AlecRabbit\Spinner\Core\Contract\IIntegerNormalizer;
10
use AlecRabbit\Spinner\Core\IntegerNormalizer;
11
use AlecRabbit\Spinner\Exception\LogicException;
12
13
final class IntegerNormalizerBuilder implements IIntegerNormalizerBuilder
14
{
15
    private ?int $divisor = null;
16
    private ?int $min = null;
17
18
    public function build(): IIntegerNormalizer
19
    {
20
        $this->validate();
21
22
        return new IntegerNormalizer(
23
            $this->divisor,
0 ignored issues
show
Bug introduced by
It seems like $this->divisor can also be of type null; however, parameter $divisor of AlecRabbit\Spinner\Core\...rmalizer::__construct() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

23
            /** @scrutinizer ignore-type */ $this->divisor,
Loading history...
24
            $this->min,
0 ignored issues
show
Bug introduced by
It seems like $this->min can also be of type null; however, parameter $min of AlecRabbit\Spinner\Core\...rmalizer::__construct() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

24
            /** @scrutinizer ignore-type */ $this->min,
Loading history...
25
        );
26
    }
27
28
    private function validate(): void
29
    {
30
        match (true) {
31
            null === $this->divisor => throw new LogicException('Divisor value is not set.'),
32
            $this->min === null => throw new LogicException('Min value is not set.'),
33
            default => null,
34
        };
35
    }
36
37
    public function withDivisor(int $divisor): IIntegerNormalizerBuilder
38
    {
39
        $clone = clone $this;
40
        $clone->divisor = $divisor;
41
        return $clone;
42
    }
43
44
    public function withMin(int $min): IIntegerNormalizerBuilder
45
    {
46
        $clone = clone $this;
47
        $clone->min = $min;
48
        return $clone;
49
    }
50
}
51