GeneralConfigBuilder   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 26
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 5 1
A withRunMethodMode() 0 5 1
A build() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlecRabbit\Spinner\Core\Config\Builder;
6
7
use AlecRabbit\Spinner\Contract\Mode\RunMethodMode;
8
use AlecRabbit\Spinner\Core\Config\Contract\Builder\IGeneralConfigBuilder;
9
use AlecRabbit\Spinner\Core\Config\Contract\IGeneralConfig;
10
use AlecRabbit\Spinner\Core\Config\GeneralConfig;
0 ignored issues
show
Bug introduced by
The type AlecRabbit\Spinner\Core\Config\GeneralConfig 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...
11
use AlecRabbit\Spinner\Exception\LogicException;
12
13
/**
14
 * @psalm-suppress PossiblyNullArgument
15
 */
16
final class GeneralConfigBuilder implements IGeneralConfigBuilder
17
{
18
    private ?RunMethodMode $runMethodMode = null;
19
20
    public function build(): IGeneralConfig
21
    {
22
        $this->validate();
23
24
        return new GeneralConfig(
25
            runMethodMode: $this->runMethodMode,
26
        );
27
    }
28
29
    private function validate(): void
30
    {
31
        match (true) {
32
            $this->runMethodMode === null => throw new LogicException('RunMethodMode is not set.'),
33
            default => null,
34
        };
35
    }
36
37
    public function withRunMethodMode(RunMethodMode $runMethodMode): IGeneralConfigBuilder
38
    {
39
        $clone = clone $this;
40
        $clone->runMethodMode = $runMethodMode;
41
        return $clone;
42
    }
43
}
44