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

Ansi8Color::assertIndex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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\Helper\Asserter;
12
13
final class Ansi8Color extends AAnsiColor
14
{
15
    /** @var array<string,int>|null */
16
    protected static ?array $colors = null;
17
18
    /** @return array<string,int> */
19
    protected static function getColors(): array
20
    {
21
        if (self::$colors === null) {
22
            self::$colors = array_flip(self::COLORS);
0 ignored issues
show
Bug introduced by
The constant AlecRabbit\Spinner\Extras\Color\Ansi8Color::COLORS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
23
        }
24
        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...
25
    }
26
27
    /**
28
     * @throws InvalidArgumentException
29
     */
30
    protected static function assertIndex(int $index): void
31
    {
32
        Asserter::assertIntColor($index, OptionStyleMode::ANSI8);
33
    }
34
}
35