Colours   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A setColour() 0 6 3
1
<?php
2
namespace SimpleLogger;
3
4
class Colours
5
{
6
    /**
7
     * Foreground colours.
8
     *
9
     * @var array
10
     */
11
    private static $FOREGROUND = [
12
        'black'         => '0;30',
13
        'dark_gray'     => '1;30',
14
        'red'           => '0;31',
15
        'light_red'     => '1;31',
16
        'green'         => '0;32',
17
        'light_green'   => '1;32',
18
        'yellow'        => '0;33',
19
        'light_yellow'  => '1;33',
20
        'blue'          => '0;34',
21
        'light_blue'    => '1;34',
22
        'purple'        => '0;35',
23
        'light_purple'  => '1:35',
24
        'cyan'          => '0:36',
25
        'light_cyan'    => '1;36',
26
        'light_gray'    => '0;37',
27
        'white'         => '1;37',
28
    ];
29
30
    /**
31
     * Background colours.
32
     *
33
     * @var array
34
     */
35
    private static $BACKGROUND = [
36
        'black'         => '40',
37
        'red'           => '41',
38
        'green'         => '42',
39
        'yellow'        => '43',
40
        'blue'          => '44',
41
        'magenta'       => '45',
42
        'cyan'          => '46',
43
        'light_gray'    => '47',
44
    ];
45
46
    /**
47
     * Colourize string.
48
     *
49
     * @param  string $string     string to colourize
50
     * @param  string $foreground foreground colour
51
     * @param  string $background background colour
52
     * @return string
53
     */
54
    final public function setColour($string, $foreground = null, $background = null)
55
    {
56
        $foreground = isset(self::$FOREGROUND[$foreground]) ? "\033[" . self::$FOREGROUND[$foreground] . "m" : "";
57
        $background = isset(self::$BACKGROUND[$background]) ? "\033[" . self::$BACKGROUND[$background] . "m" : "";
58
        $lineending = "\033[0m";
59
        return "{$foreground}{$background}{$string}{$lineending}";
60
    }
61
}
62