RevolverConfigBuilder::withTolerance()   A
last analyzed

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
namespace AlecRabbit\Spinner\Core\Config\Builder;
6
7
use AlecRabbit\Spinner\Core\Config\Contract\Builder\IRevolverConfigBuilder;
8
use AlecRabbit\Spinner\Core\Config\Contract\IRevolverConfig;
9
use AlecRabbit\Spinner\Core\Config\RevolverConfig;
0 ignored issues
show
Bug introduced by
The type AlecRabbit\Spinner\Core\Config\RevolverConfig 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\Core\Contract\ITolerance;
11
use AlecRabbit\Spinner\Exception\LogicException;
12
13
/**
14
 * @psalm-suppress PossiblyNullArgument
15
 */
16
final class RevolverConfigBuilder implements IRevolverConfigBuilder
17
{
18
    private ?ITolerance $tolerance = null;
19
20
    public function build(): IRevolverConfig
21
    {
22
        $this->validate();
23
24
        return new RevolverConfig(
25
            tolerance: $this->tolerance,
26
        );
27
    }
28
29
    /**
30
     * @throws LogicException
31
     */
32
    private function validate(): void
33
    {
34
        match (true) {
35
            $this->tolerance === null => throw new LogicException('Tolerance is not set.'),
36
            default => null,
37
        };
38
    }
39
40
    public function withTolerance(ITolerance $tolerance): IRevolverConfigBuilder
41
    {
42
        $clone = clone $this;
43
        $clone->tolerance = $tolerance;
44
        return $clone;
45
    }
46
}
47