ConsoleCursorBuilder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
c 0
b 0
f 0
dl 0
loc 36
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A withCursorVisibilityMode() 0 5 1
A build() 0 7 1
A validate() 0 6 1
A withBuffer() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlecRabbit\Spinner\Core\Builder;
6
7
use AlecRabbit\Spinner\Contract\Mode\CursorVisibilityMode;
8
use AlecRabbit\Spinner\Core\Builder\Contract\IConsoleCursorBuilder;
9
use AlecRabbit\Spinner\Core\Output\ConsoleCursor;
0 ignored issues
show
Bug introduced by
The type AlecRabbit\Spinner\Core\Output\ConsoleCursor 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\Output\Contract\IBuffer;
11
use AlecRabbit\Spinner\Core\Output\Contract\IConsoleCursor;
12
use AlecRabbit\Spinner\Exception\LogicException;
13
14
/**
15
 * @psalm-suppress PossiblyNullArgument
16
 */
17
final class ConsoleCursorBuilder implements IConsoleCursorBuilder
18
{
19
    private ?CursorVisibilityMode $cursorVisibilityMode = null;
20
    private ?IBuffer $buffer = null;
21
22
    public function build(): IConsoleCursor
23
    {
24
        $this->validate();
25
26
        return new ConsoleCursor(
27
            $this->buffer,
28
            $this->cursorVisibilityMode,
29
        );
30
    }
31
32
    private function validate(): void
33
    {
34
        match (true) {
35
            $this->buffer === null => throw new LogicException('Buffer is not set.'),
36
            $this->cursorVisibilityMode === null => throw new LogicException('CursorVisibilityMode is not set.'),
37
            default => null,
38
        };
39
    }
40
41
    public function withBuffer(IBuffer $buffer): IConsoleCursorBuilder
42
    {
43
        $clone = clone $this;
44
        $clone->buffer = $buffer;
45
        return $clone;
46
    }
47
48
    public function withCursorVisibilityMode(CursorVisibilityMode $cursorVisibilityMode): IConsoleCursorBuilder
49
    {
50
        $clone = clone $this;
51
        $clone->cursorVisibilityMode = $cursorVisibilityMode;
52
        return $clone;
53
    }
54
}
55