WidgetRevolverConfigBuilder::withCharPalette()   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
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
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\IWidgetRevolverConfigBuilder;
8
use AlecRabbit\Spinner\Core\Config\Contract\IRevolverConfig;
9
use AlecRabbit\Spinner\Core\Config\Contract\IWidgetRevolverConfig;
10
use AlecRabbit\Spinner\Core\Config\WidgetRevolverConfig;
0 ignored issues
show
Bug introduced by
The type AlecRabbit\Spinner\Core\...ig\WidgetRevolverConfig 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\Core\Palette\Contract\IPalette;
12
use AlecRabbit\Spinner\Exception\LogicException;
13
14
/**
15
 * @psalm-suppress PossiblyNullArgument
16
 */
17
final class WidgetRevolverConfigBuilder implements IWidgetRevolverConfigBuilder
18
{
19
    private ?IPalette $stylePalette = null;
20
    private ?IPalette $charPalette = null;
21
    private ?IRevolverConfig $revolverConfig = null;
22
23
    public function build(): IWidgetRevolverConfig
24
    {
25
        $this->validate();
26
27
        return new WidgetRevolverConfig(
28
            stylePalette: $this->stylePalette,
29
            charPalette: $this->charPalette,
30
            revolverConfig: $this->revolverConfig,
31
        );
32
    }
33
34
    private function validate(): void
35
    {
36
        match (true) {
37
            $this->stylePalette === null => throw new LogicException('Style palette is not set.'),
38
            $this->charPalette === null => throw new LogicException('Char palette is not set.'),
39
            $this->revolverConfig === null => throw new LogicException('Revolver config is not set.'),
40
            default => null,
41
        };
42
    }
43
44
    public function withStylePalette(IPalette $palette): IWidgetRevolverConfigBuilder
45
    {
46
        $clone = clone $this;
47
        $clone->stylePalette = $palette;
48
        return $clone;
49
    }
50
51
    public function withCharPalette(IPalette $palette): IWidgetRevolverConfigBuilder
52
    {
53
        $clone = clone $this;
54
        $clone->charPalette = $palette;
55
        return $clone;
56
    }
57
58
    public function withRevolverConfig(IRevolverConfig $revolverConfig): IWidgetRevolverConfigBuilder
59
    {
60
        $clone = clone $this;
61
        $clone->revolverConfig = $revolverConfig;
62
        return $clone;
63
    }
64
}
65