LinkerConfigBuilder   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 6 1
A validate() 0 5 1
A withLinkerMode() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlecRabbit\Spinner\Core\Config\Builder;
6
7
use AlecRabbit\Spinner\Contract\Mode\LinkerMode;
8
use AlecRabbit\Spinner\Core\Config\Contract\Builder\ILinkerConfigBuilder;
9
use AlecRabbit\Spinner\Core\Config\Contract\ILinkerConfig;
10
use AlecRabbit\Spinner\Core\Config\LinkerConfig;
0 ignored issues
show
Bug introduced by
The type AlecRabbit\Spinner\Core\Config\LinkerConfig 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 LinkerConfigBuilder implements ILinkerConfigBuilder
17
{
18
    private ?LinkerMode $linkerMode = null;
19
20
    public function build(): ILinkerConfig
21
    {
22
        $this->validate();
23
24
        return new LinkerConfig(
25
            linkerMode: $this->linkerMode,
26
        );
27
    }
28
29
    /**
30
     * @throws LogicException
31
     */
32
    private function validate(): void
33
    {
34
        match (true) {
35
            $this->linkerMode === null => throw new LogicException('LinkerMode is not set.'),
36
            default => null,
37
        };
38
    }
39
40
    public function withLinkerMode(LinkerMode $linkerMode): ILinkerConfigBuilder
41
    {
42
        $clone = clone $this;
43
        $clone->linkerMode = $linkerMode;
44
        return $clone;
45
    }
46
}
47