Completed
Push — develop ( fa94ad...c6900b )
by Michał
16:07
created

Style::warningMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 3
b 0
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BlueConsole;
6
7
use Symfony\Component\Console\Style\SymfonyStyle;
8
9
class Style extends SymfonyStyle
10
{
11
    use AdditionalStyles;
12
13
    public const DAY_SECONDS = 86400;
14
15
    /**
16
     * @param bool $newLine
17
     * @return Style
18
     * @throws \Exception
19
     */
20 4
    public function timer(bool $newLine = true): self
21
    {
22 4
        $this->write($this->getTimer());
23
24 4
        if ($newLine) {
25 4
            $this->newLine();
26
        }
27
28 4
        return $this;
29
    }
30
31
    /**
32
     * @param string $section
33
     * @param string $message
34
     * @param string $style
35
     * @return $this
36
     * @throws \Exception
37
     * @throws \InvalidArgumentException
38
     */
39 4
    public function formatSection(string $section, string $message, string $style = 'info'): self
40
    {
41 4
        $timer = $this->getTimer(true);
42
43 4
        $this->writeln(
44 4
            $timer . $this->formatter->formatSection(
45 4
                $section,
46 2
                $message,
47 2
                $style
48
            )
49
        );
50
51 4
        return $this;
52
    }
53
54
    /**
55
     * @param string|array $messages
56
     * @param string $style
57
     * @param bool $large
58
     * @return $this
59
     * @throws \Exception
60
     * @throws \InvalidArgumentException
61
     */
62 12
    public function formatBlock($messages, string $style, bool $large = false): self
63
    {
64 12
        $timer = $this->getTimer(true);
65
66 12
        if (!\is_array($messages)) {
67 4
            $messages = [$messages];
68
        }
69
70 12
        foreach ($messages as $message) {
71 12
            $this->writeln(
72 12
                $timer . $this->formatter->formatBlock(
73 12
                    $message,
74 6
                    $style,
75 6
                    $large
76
                )
77
            );
78
        }
79
80 12
        return $this;
81
    }
82
83
    /**
84
     * @param array $message
85
     * @return $this
86
     * @throws \Exception
87
     * @throws \InvalidArgumentException
88
     */
89 4
    public function errorLine(array $message): self
90
    {
91 4
        return $this->formatBlock($message, 'error');
92
    }
93
94
    /**
95
     * @param $message
96
     * @return $this
97
     * @throws \InvalidArgumentException
98
     * @throws \Exception
99
     */
100 12
    public function okMessage(string $message): self
101
    {
102 12
        return $this->renderBlock('  <info>OK</info>  ', $message);
103
    }
104
105
    /**
106
     * @param $message
107
     * @return $this
108
     * @throws \InvalidArgumentException
109
     * @throws \Exception
110
     */
111 12
    public function errorMessage(string $message): self
112
    {
113 12
        return $this->renderBlock(' <fg=red>FAIL</> ', $message);
114
    }
115
116
    /**
117
     * @param string $message
118
     * @return $this
119
     * @throws \InvalidArgumentException
120
     * @throws \Exception
121
     */
122 12
    public function warningMessage(string $message): self
123
    {
124 12
        return $this->renderBlock(' <comment>WARN</comment> ', $message);
125
    }
126
127
    /**
128
     * @param string $message
129
     * @return $this
130
     * @throws \InvalidArgumentException
131
     * @throws \Exception
132
     */
133 12
    public function infoMessage(string $message): self
134
    {
135 12
        return $this->renderBlock(' <fg=blue>INFO</> ', $message);
136
    }
137
138
    /**
139
     * @param string $block
140
     * @param string $message
141
     * @return Style
142
     * @throws \Exception
143
     */
144 48
    public function renderBlock(string $block, string $message): self
145
    {
146 48
        $timer = $this->getTimer(true);
147 48
        $alignment = $this->align(8, $this->align);
148
149 48
        $this->write("{$timer}[$block]");
150 48
        $this->write($alignment);
151 48
        $this->writeln($message);
152
153 48
        return $this;
154
    }
155
156
    /**
157
     * @param string $message
158
     * @return $this
159
     * @throws \InvalidArgumentException
160
     * @throws \Exception
161
     */
162 4
    public function note($message): self
163
    {
164 4
        return $this->genericBlock($message, 'blue', 'note');
165
    }
166
167
    /**
168
     * @param string $message
169
     * @return $this
170
     * @throws \InvalidArgumentException
171
     * @throws \Exception
172
     */
173 4
    public function caution($message): self
174
    {
175 4
        return $this->genericBlock($message, 'magenta', 'caution');
176
    }
177
178
    /**
179
     * @param string $message
180
     * @return $this
181
     * @throws \InvalidArgumentException
182
     * @throws \Exception
183
     */
184 4
    public function success($message): self
185
    {
186 4
        return $this->genericBlock($message, 'green', 'success');
187
    }
188
189
    /**
190
     * @param string $message
191
     * @return $this
192
     * @throws \InvalidArgumentException
193
     * @throws \Exception
194
     */
195 4
    public function warning($message): self
196
    {
197 4
        return $this->genericBlock($message, 'yellow', 'warning');
198
    }
199
200
    /**
201
     * @param string $message
202
     * @return $this
203
     * @throws \InvalidArgumentException
204
     * @throws \Exception
205
     */
206 4
    public function error($message): self
207
    {
208 4
        return $this->genericBlock($message, 'red', 'error');
209
    }
210
211
    /**
212
     * @param string $message
213
     * @param string $background
214
     * @param string|null $type
215
     * @param int $length
216
     * @return $this
217
     * @throws \InvalidArgumentException
218
     * @throws \Exception
219
     */
220 28
    public function genericBlock(string $message, string $background, ?string $type, int $length = 100): self
221
    {
222 28
        if (\trim($type) === '') {
223 4
            return $this;
224
        }
225
226 24
        $type = \strtoupper($type);
227 24
        $alignment = $this->align(0, $length);
228 24
        $alignmentMessage = $this->align($message, $length - (\mb_strlen($type) + 5));
229
230 24
        $timer = $this->getTimer(true);
231 24
        $timer ? $this->writeln($timer) : null;
232
233 24
        $this->writeln("<bg=$background>$alignment</>");
234 24
        $this->writeln("<fg=white;bg=$background>  [$type] $message$alignmentMessage</>");
235 24
        $this->writeln("<bg=$background>$alignment</>");
236 24
        $this->newLine();
237
238 24
        return $this;
239
    }
240
241
    public function longRunCommand(string $command): void
0 ignored issues
show
Unused Code introduced by
The parameter $command is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

241
    public function longRunCommand(/** @scrutinizer ignore-unused */ string $command): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
242
    {
243
        //[ ***  ]
244
    }
245
246
    /**
247
     * @todo add multi line block
248
     */
249
250
    /*
251
        http://symfony.com/doc/current/components/console/helpers/formatterhelper.html
252
        https://symfony.com/doc/current/console/style.html
253
    */
254
}
255