WidgetRevolverBuilder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
c 0
b 0
f 0
dl 0
loc 46
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 8 1
A validate() 0 7 1
A withStyleRevolver() 0 5 1
A withCharRevolver() 0 5 1
A withTolerance() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlecRabbit\Spinner\Core\Widget\Builder;
6
7
use AlecRabbit\Spinner\Core\Contract\ITolerance;
8
use AlecRabbit\Spinner\Core\Revolver\A\ARevolverBuilder;
9
use AlecRabbit\Spinner\Core\Revolver\Contract\IFrameRevolver;
10
use AlecRabbit\Spinner\Core\Widget\Contract\IWidgetRevolver;
11
use AlecRabbit\Spinner\Core\Widget\Contract\IWidgetRevolverBuilder;
12
use AlecRabbit\Spinner\Core\Widget\WidgetRevolver;
13
use AlecRabbit\Spinner\Exception\LogicException;
14
15
/**
16
 * @psalm-suppress PossiblyNullArgument
17
 */
18
final class WidgetRevolverBuilder extends ARevolverBuilder implements IWidgetRevolverBuilder
19
{
20
    private ?IFrameRevolver $styleRevolver = null;
21
    private ?IFrameRevolver $charRevolver = null;
22
    private ?ITolerance $tolerance = null;
23
24
    public function build(): IWidgetRevolver
25
    {
26
        $this->validate();
27
28
        return new WidgetRevolver(
29
            $this->styleRevolver,
0 ignored issues
show
Bug introduced by
It seems like $this->styleRevolver can also be of type null; however, parameter $style of AlecRabbit\Spinner\Core\...Revolver::__construct() does only seem to accept AlecRabbit\Spinner\Core\...lver\Contract\IRevolver, 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

29
            /** @scrutinizer ignore-type */ $this->styleRevolver,
Loading history...
30
            $this->charRevolver,
0 ignored issues
show
Bug introduced by
It seems like $this->charRevolver can also be of type null; however, parameter $character of AlecRabbit\Spinner\Core\...Revolver::__construct() does only seem to accept AlecRabbit\Spinner\Core\...lver\Contract\IRevolver, 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

30
            /** @scrutinizer ignore-type */ $this->charRevolver,
Loading history...
31
            $this->tolerance,
0 ignored issues
show
Bug introduced by
It seems like $this->tolerance can also be of type null; however, parameter $tolerance of AlecRabbit\Spinner\Core\...Revolver::__construct() does only seem to accept AlecRabbit\Spinner\Core\Contract\ITolerance, 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

31
            /** @scrutinizer ignore-type */ $this->tolerance,
Loading history...
32
        );
33
    }
34
35
    protected function validate(): void
36
    {
37
        match (true) {
38
            $this->styleRevolver === null => throw new LogicException('Style revolver is not set.'),
39
            $this->charRevolver === null => throw new LogicException('Character revolver is not set.'),
40
            $this->tolerance === null => throw new LogicException('Tolerance is not set.'),
41
            default => null,
42
        };
43
    }
44
45
    public function withStyleRevolver(IFrameRevolver $styleRevolver): IWidgetRevolverBuilder
46
    {
47
        $clone = clone $this;
48
        $clone->styleRevolver = $styleRevolver;
49
        return $clone;
50
    }
51
52
    public function withCharRevolver(IFrameRevolver $charRevolver): IWidgetRevolverBuilder
53
    {
54
        $clone = clone $this;
55
        $clone->charRevolver = $charRevolver;
56
        return $clone;
57
    }
58
59
    public function withTolerance(ITolerance $tolerance): IWidgetRevolverBuilder
60
    {
61
        $clone = clone $this;
62
        $clone->tolerance = $tolerance;
63
        return $clone;
64
    }
65
}
66