AbstractColorManager   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 2 Features 0
Metric Value
wmc 4
c 4
b 2
f 0
lcom 0
cbo 0
dl 0
loc 47
ccs 5
cts 5
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A color() 0 12 2
A getKnownColors() 0 5 1
A getColorClass() 0 5 1
1
<?php
2
3
namespace Matks\Vivian\Color;
4
5
use Exception;
6
7
/**
8
 * Abstract Color manager
9
 */
10
abstract class AbstractColorManager
11
{
12
    const ANSI_ESCAPE_CODE_BEGIN = "\033[";
13
    const ANSI_ESCAPE_CODE_END   = 'm';
14
15
    /**
16
     * Get color
17
     *
18
     * @param int $colorID
19
     *
20
     * @return EscapeAttribute color
21
     */
22
    public static function color($colorID)
23
    {
24 1
        if (!in_array($colorID, static::getKnownColors())) {
25 1
            throw new Exception("Unknown color ID $colorID");
26
        }
27
28 1
        $colorClass = static::getColorClass();
29
30 1
        $color = new $colorClass($colorID);
31
32 1
        return $color;
33
    }
34
35
    /**
36
     * Get allowed colors
37
     *
38
     * @return string[]
39
     */
40
    public static function getKnownColors()
41
    {
42
        // it is impossible to make abstract static functions since PHP 5.2
43
        throw new \RuntimeException('Do not use AbstractColorManager, use its children instead');
44
    }
45
46
    /**
47
     * Get Color class
48
     *
49
     * @return string
50
     */
51
    public static function getColorClass()
52
    {
53
        // it is impossible to make abstract static functions since PHP 5.2
54
        throw new \RuntimeException('Do not use AbstractColorManager, use its children instead');
55
    }
56
}
57