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

FrameRevolverBuilder::withTolerance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
6
namespace AlecRabbit\Spinner\Core\Revolver;
7
8
use AlecRabbit\Spinner\Contract\IInterval;
9
use AlecRabbit\Spinner\Core\Contract\IFrameCollection;
10
use AlecRabbit\Spinner\Core\Revolver\Contract\IFrameRevolver;
11
use AlecRabbit\Spinner\Core\Revolver\Contract\IFrameRevolverBuilder;
12
use AlecRabbit\Spinner\Exception\LogicException;
13
14
final class FrameRevolverBuilder implements IFrameRevolverBuilder
15
{
16
    private ?IFrameCollection $frames = null;
17
    private ?IInterval $interval = null;
18
    private ?int $tolerance = null;
19
20
    public function build(): IFrameRevolver
21
    {
22
        $this->validate();
23
24
        return
25
            new FrameCollectionRevolver(
26
                $this->frames,
0 ignored issues
show
Bug introduced by
It seems like $this->frames can also be of type null; however, parameter $frameCollection of AlecRabbit\Spinner\Core\...Revolver::__construct() does only seem to accept AlecRabbit\Spinner\Core\Contract\IFrameCollection, 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

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

27
                /** @scrutinizer ignore-type */ $this->interval,
Loading history...
28
                $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 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

28
                /** @scrutinizer ignore-type */ $this->tolerance,
Loading history...
29
            );
30
    }
31
32
    private function validate(): void
33
    {
34
        match (true) {
35
            $this->frames === null => throw new LogicException('Frame collection is not set.'),
36
            $this->interval === null => throw new LogicException('Interval is not set.'),
37
            $this->tolerance === null => throw new LogicException('Tolerance is not set.'),
38
            default => null,
39
        };
40
    }
41
42
    public function withFrameCollection(IFrameCollection $frames): IFrameRevolverBuilder
43
    {
44
        $clone = clone $this;
45
        $clone->frames = $frames;
46
        return $clone;
47
    }
48
49
    public function withInterval(IInterval $interval): IFrameRevolverBuilder
50
    {
51
        $clone = clone $this;
52
        $clone->interval = $interval;
53
        return $clone;
54
    }
55
56
    public function withTolerance(int $tolerance): IFrameRevolverBuilder
57
    {
58
        $clone = clone $this;
59
        $clone->tolerance = $tolerance;
60
        return $clone;
61
    }
62
}
63