Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 23
Output
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 8
156
0.00% covered (danger)
0.00%
0 / 23
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 info
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 line
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
 comment
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 question
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 error
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 warn
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 5
 parseVerbosity
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 5
1<?php
2
3namespace Qmp\Laravel\DockerLauncher\Docker;
4
5use Symfony\Component\Console\Formatter\OutputFormatterStyle;
6use Symfony\Component\Console\Output\OutputInterface;
7
8class Output
9{
10    private $output;
11
12
13    /**
14     * The default verbosity of output commands.
15     *
16     * @var int
17     */
18    protected $verbosity = OutputInterface::VERBOSITY_NORMAL;
19
20    /**
21     * The mapping between human readable verbosity levels and Symfony's OutputInterface.
22     *
23     * @var array
24     */
25    protected $verbosityMap = [
26        'v' => OutputInterface::VERBOSITY_VERBOSE,
27        'vv' => OutputInterface::VERBOSITY_VERY_VERBOSE,
28        'vvv' => OutputInterface::VERBOSITY_DEBUG,
29        'quiet' => OutputInterface::VERBOSITY_QUIET,
30        'normal' => OutputInterface::VERBOSITY_NORMAL,
31    ];
32
33    public function __construct(OutputInterface $output)
34    {
35        $this->output = $output;
36    }
37
38
39    /**
40     * Write a string as information output.
41     *
42     * @param  string  $string
43     * @param  null|int|string  $verbosity
44     * @return void
45     */
46    public function info($string, $verbosity = null)
47    {
48        $this->line($string, 'info', $verbosity);
49    }
50
51    /**
52     * Write a string as standard output.
53     *
54     * @param  string  $string
55     * @param  string  $style
56     * @param  null|int|string  $verbosity
57     * @return void
58     */
59    public function line($string, $style = null, $verbosity = null)
60    {
61        $styled = $style ? "<$style>$string</$style>" : $string;
62
63        $this->output->writeln($styled, $this->parseVerbosity($verbosity));
64    }
65
66    /**
67     * Write a string as comment output.
68     *
69     * @param  string  $string
70     * @param  null|int|string  $verbosity
71     * @return void
72     */
73    public function comment($string, $verbosity = null)
74    {
75        $this->line($string, 'comment', $verbosity);
76    }
77
78    /**
79     * Write a string as question output.
80     *
81     * @param  string  $string
82     * @param  null|int|string  $verbosity
83     * @return void
84     */
85    public function question($string, $verbosity = null)
86    {
87        $this->line($string, 'question', $verbosity);
88    }
89
90    /**
91     * Write a string as error output.
92     *
93     * @param  string  $string
94     * @param  null|int|string  $verbosity
95     * @return void
96     */
97    public function error($string, $verbosity = null)
98    {
99        $this->line($string, 'error', $verbosity);
100    }
101
102    /**
103     * Write a string as warning output.
104     *
105     * @param  string  $string
106     * @param  null|int|string  $verbosity
107     * @return void
108     */
109    public function warn($string, $verbosity = null)
110    {
111        if (! $this->output->getFormatter()->hasStyle('warning')) {
112            $style = new OutputFormatterStyle('yellow');
113
114            $this->output->getFormatter()->setStyle('warning', $style);
115        }
116
117        $this->line($string, 'warning', $verbosity);
118    }
119
120    /**
121     * Get the verbosity level in terms of Symfony's OutputInterface level.
122     *
123     * @param  string|int  $level
124     * @return int
125     */
126    protected function parseVerbosity($level = null)
127    {
128        if (isset($this->verbosityMap[$level])) {
129            $level = $this->verbosityMap[$level];
130        } elseif (! is_int($level)) {
131            $level = $this->verbosity;
132        }
133
134        return $level;
135    }
136}