BaseCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 8
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addStyles() 0 4 1
A overwrite() 0 13 3
1
<?php
2
3
namespace AlexWells\ApiDocsGenerator\Commands;
4
5
use Illuminate\Console\Command;
6
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
7
8
class BaseCommand extends Command
9
{
10
    /**
11
     * Overwrite previous line with new message.
12
     *
13
     * @param string $string
14
     * @param string $style
15
     * @param null|int|string $verbosity
16
     */
17
    protected function overwrite($string, $style = null, $verbosity = null)
18
    {
19
        if ($this->output->isDecorated()) {
20
            // Move the cursor to the beginning of the line
21
            $this->output->write("\x0D");
22
23
            // Erase the line
24
            $this->output->write("\x1B[2K");
25
        }
26
27
        $styled = $style ? "<$style>$string</$style>" : $string;
28
29
        $this->output->write($styled, false, $this->parseVerbosity($verbosity));
30
    }
31
32
    /**
33
     * Add common styles.
34
     */
35
    protected function addStyles()
36
    {
37
        $this->output->getFormatter()->setStyle('warn', new OutputFormatterStyle('yellow'));
38
        $this->output->getFormatter()->setStyle('red', new OutputFormatterStyle('red'));
39
    }
40
}
41