Passed
Push — master ( de3d61...be839c )
by Alec
13:42 queued 13s
created

Ansi4Color   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 22
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getColors() 0 6 2
A assertIndex() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
6
namespace AlecRabbit\Spinner\Extras\Color;
7
8
use AlecRabbit\Spinner\Contract\Option\OptionStyleMode;
9
use AlecRabbit\Spinner\Exception\InvalidArgumentException;
10
use AlecRabbit\Spinner\Extras\Color\A\AAnsiColor;
11
use AlecRabbit\Spinner\Extras\Color\Mixin\Ansi8ColorTableTrait;
12
use AlecRabbit\Spinner\Helper\Asserter;
13
14
final class Ansi4Color extends AAnsiColor
15
{
16
    use Ansi8ColorTableTrait;
17
18
    /** @var array<string,int>|null */
19
    protected static ?array $colors = null;
20
21
    /** @return array<string,int> */
22
    protected static function getColors(): array
23
    {
24
        if (self::$colors === null) {
25
            self::$colors = array_flip(array_slice(self::COLORS, 0, 16));
0 ignored issues
show
Bug introduced by
The constant AlecRabbit\Spinner\Extras\Color\Ansi4Color::COLORS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
26
        }
27
        return self::$colors;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::colors could return the type null which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
28
    }
29
30
    /**
31
     * @throws InvalidArgumentException
32
     */
33
    protected static function assertIndex(int $index): void
34
    {
35
        Asserter::assertIntColor($index, OptionStyleMode::ANSI4);
36
    }
37
}
38