EnhancedOutput::error()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 3
1
<?php namespace Tequilarapido\Cli;
2
3
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
4
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
5
use Symfony\Component\Console\Output\ConsoleOutput;
6
7
/**
8
 * Class EnhancedOutput
9
 *
10
 * @implements Symfony\Component\Console\Output\OutputInterface
11
 * @package Teq\Components
12
 */
13
class EnhancedOutput extends ConsoleOutput
14
{
15
16
    public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
17
    {
18
        parent::__construct($verbosity, $decorated, $formatter);
19
20
        $style = new OutputFormatterStyle('green');
21
        $this->getFormatter()->setStyle('success', $style);
22
    }
23
24
    public function title($title)
25
    {
26
        $this->writeln("");
27
        $this->writeln("");
28
        $this->writeln("-------------------------------------------------");
29
        $this->writeln(" $title");
30
        $this->writeln("-------------------------------------------------");
31
    }
32
33
    public function info($message = '', $space = false)
34
    {
35
        $message = $this->space($space) . ' ' . $message;
36
        $this->writeln("<info>$message</info>");
37
    }
38
39
    public function success($message = '', $space = false)
40
    {
41
        $message = $this->space($space) . ' ' . $message;
42
        $this->writeln("<success>$message</success>");
43
    }
44
45
    public function warn($message = '', $space = false)
46
    {
47
        $message = $this->space($space) . '[WARN] ' . $message;
48
        $this->writeln("<comment>$message</comment>");
49
    }
50
51
    public function error($message = '', $exitOnError = true, $space = false)
52
    {
53
        $message = $this->space($space) . '[ERROR] ' . $message;
54
        $this->writeln("<error>$message</error>");
55
56
        if ($exitOnError) {
57
            throw new \Exception('[ERROR] Execution aborted!');
58
        }
59
    }
60
61
    /**
62
     * @param boolean $space
63
     */
64
    private function space($space)
65
    {
66
        return $space ? "\n\n\n" : "";
67
    }
68
69
}