GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 3.0 ( 827fa4...7abdc1 )
by Vermeulen
02:29
created

Cli::displayMsgNL()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 2
eloc 9
nc 2
nop 4
1
<?php
2
3
namespace BFW\Helpers;
4
5
use \Exception;
6
7
/**
8
 * Helpers for cli applications
9
 */
10
class Cli
11
{
12
    /**
13
     * Display a message in the console without a line break
14
     * 
15
     * @param string $msg Message to display
16
     * @param string $colorTxt (default "white") Text color
17
     * @param string $colorBg (default "black") Background color
18
     * @param string $style (default "normal") Style for the message (bold etc)
19
     * 
20
     * @return void
21
     */
22
    public static function displayMsg(
23
        $msg,
24
        $colorTxt = 'white',
25
        $colorBg = 'black',
26
        $style = 'normal'
27
    ) {
28
        if (func_num_args() === 1) {
29
            echo $msg;
30
            return;
31
        }
32
        
33
        //Gestion cas avec couleur
34
        $styleNum    = self::styleForShell($style);
35
        $colorTxtNum = self::colorForShell($colorTxt, 'txt');
36
        $colorBgNum  = self::colorForShell($colorBg, 'bg');
37
38
        echo "\033[".$styleNum.";".$colorBgNum.";".$colorTxtNum."m"
39
            .$msg
40
            ."\033[0m";
41
    }
42
    
43
    /**
44
     * Display a message in the console with a line break
45
     * 
46
     * @param string $msg Message to display
47
     * @param string $colorTxt (default "white") Text color
48
     * @param string $colorBg (default "black") Background color
49
     * @param string $style (default "normal") Style for the message (bold etc)
50
     * 
51
     * @return void
52
     */
53
    public static function displayMsgNL(
54
        $msg,
55
        $colorTxt = 'white',
56
        $colorBg = 'black',
57
        $style = 'normal'
58
    ) {
59
        if (func_num_args() === 1) {
60
            self::displayMsg($msg."\n");
61
            return;
62
        }
63
        
64
        self::displayMsg($msg."\n", $colorTxt, $colorBg, $style);
65
    }
66
67
    /**
68
     * Convert text color to shell value
69
     * 
70
     * @param string $color The humain color text
71
     * @param string $type ("txt"|"bg") If the color is for text of background
72
     * 
73
     * @return integer
74
     * 
75
     * @throws Exception If the color is not available
76
     */
77
    protected static function colorForShell($color, $type)
78
    {
79
        $colorList = [
80
            'black'   => 0,
81
            'red'     => 1,
82
            'green'   => 2,
83
            'yellow'  => 3,
84
            'blue'    => 4,
85
            'magenta' => 5,
86
            'cyan'    => 6,
87
            'white'   => 7
88
        ];
89
90
        if (!isset($colorList[$color])) {
91
            throw new Exception('Color '.$color.' is not available.');
92
        }
93
94
        //Text color
95
        if ($type === 'txt') {
96
            return $colorList[$color] + 30;
97
        }
98
        
99
        //Background color
100
        return $colorList[$color] + 40;
101
    }
102
103
    /**
104
     * Convert a humain style text to shell value
105
     * 
106
     * @param string $style The style value
107
     * 
108
     * @return integer
109
     * 
110
     * @throws Exception If the style is not available
111
     */
112
    protected static function styleForShell($style)
113
    {
114
        $styleList = [
115
            'normal'        => 0,
116
            'bold'          => 1,
117
            'not-bold'      => 21,
118
            'underline'     => 4,
119
            'not-underline' => 24,
120
            'blink'         => 5,
121
            'not-blink'     => 25,
122
            'reverse'       => 7,
123
            'not-reverse'   => 27
124
        ];
125
126
        if (!isset($styleList[$style])) {
127
            throw new Exception('Style '.$style.' is not available.');
128
        }
129
130
        return $styleList[$style];
131
    }
132
}
133