Passed
Push — master ( 4a1742...ff2740 )
by Alec
03:07 queued 34s
created

Core/Widget/Builder/WidgetCompositeBuilder.php (4 issues)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlecRabbit\Spinner\Core\Widget\Builder;
6
7
use AlecRabbit\Spinner\Contract\IFrame;
8
use AlecRabbit\Spinner\Core\Contract\IIntervalComparator;
9
use AlecRabbit\Spinner\Core\Widget\Builder\A\AWidgetBuilder;
10
use AlecRabbit\Spinner\Core\Widget\Contract\IWidgetComposite;
11
use AlecRabbit\Spinner\Core\Widget\Contract\IWidgetCompositeBuilder;
12
use AlecRabbit\Spinner\Core\Widget\Contract\IWidgetRevolver;
13
use AlecRabbit\Spinner\Core\Widget\WidgetComposite;
14
use AlecRabbit\Spinner\Exception\LogicException;
15
16
/**
17
 * @psalm-suppress PossiblyNullArgument
18
 */
19
final class WidgetCompositeBuilder extends AWidgetBuilder implements IWidgetCompositeBuilder
20
{
21
    private ?IIntervalComparator $intervalComparator = null;
22
23
    public function build(): IWidgetComposite
24
    {
25
        $this->validate();
26
27
        return new WidgetComposite(
28
            revolver: $this->revolver,
0 ignored issues
show
It seems like $this->revolver can also be of type null; however, parameter $revolver of AlecRabbit\Spinner\Core\...omposite::__construct() does only seem to accept AlecRabbit\Spinner\Core\...ontract\IWidgetRevolver, 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

28
            /** @scrutinizer ignore-type */ revolver: $this->revolver,
Loading history...
29
            leadingSpacer: $this->leadingSpacer,
0 ignored issues
show
It seems like $this->leadingSpacer can also be of type null; however, parameter $leadingSpacer of AlecRabbit\Spinner\Core\...omposite::__construct() does only seem to accept AlecRabbit\Spinner\Contract\IFrame, 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 */ leadingSpacer: $this->leadingSpacer,
Loading history...
30
            trailingSpacer: $this->trailingSpacer,
0 ignored issues
show
It seems like $this->trailingSpacer can also be of type null; however, parameter $trailingSpacer of AlecRabbit\Spinner\Core\...omposite::__construct() does only seem to accept AlecRabbit\Spinner\Contract\IFrame, 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 */ trailingSpacer: $this->trailingSpacer,
Loading history...
31
            intervalComparator: $this->intervalComparator,
0 ignored issues
show
It seems like $this->intervalComparator can also be of type null; however, parameter $intervalComparator of AlecRabbit\Spinner\Core\...omposite::__construct() does only seem to accept AlecRabbit\Spinner\Core\...act\IIntervalComparator, 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 */ intervalComparator: $this->intervalComparator,
Loading history...
32
        );
33
    }
34
35
    protected function validate(): void
36
    {
37
        parent::validate();
38
39
        match (true) {
40
            $this->intervalComparator === null => throw new LogicException('Interval comparator is not set.'),
41
            default => null,
42
        };
43
    }
44
45
    public function withWidgetRevolver(IWidgetRevolver $revolver): IWidgetCompositeBuilder
46
    {
47
        $clone = clone $this;
48
        $clone->revolver = $revolver;
49
        return $clone;
50
    }
51
52
    public function withLeadingSpacer(IFrame $leadingSpacer): IWidgetCompositeBuilder
53
    {
54
        $clone = clone $this;
55
        $clone->leadingSpacer = $leadingSpacer;
56
        return $clone;
57
    }
58
59
    public function withTrailingSpacer(IFrame $trailingSpacer): IWidgetCompositeBuilder
60
    {
61
        $clone = clone $this;
62
        $clone->trailingSpacer = $trailingSpacer;
63
        return $clone;
64
    }
65
66
    public function withIntervalComparator(IIntervalComparator $intervalComparator): IWidgetCompositeBuilder
67
    {
68
        $clone = clone $this;
69
        $clone->intervalComparator = $intervalComparator;
70
        return $clone;
71
    }
72
}
73