Completed
Push — master ( 6629c2...9cd779 )
by Greg
02:34
created

OutputAwareTrait::stderr()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Robo\Common;
4
5
use Symfony\Component\Console\Output\ConsoleOutputInterface;
6
use Symfony\Component\Console\Output\NullOutput;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
trait OutputAwareTrait
10
{
11
    /**
12
     * @var \Symfony\Component\Console\Output\OutputInterface
13
     */
14
    protected $output;
15
16
    /**
17
     * @param \Symfony\Component\Console\Output\OutputInterface $output
18
     *
19
     * @return $this
20
     *
21
     * @see \Robo\Contract\OutputAwareInterface::setOutput()
22
     */
23
    public function setOutput(OutputInterface $output)
24
    {
25
        $this->output = $output;
26
27
        return $this;
28
    }
29
30
    /**
31
     * @return \Symfony\Component\Console\Output\OutputInterface
32
     */
33
    protected function output()
34
    {
35
        if (!isset($this->output)) {
36
            $this->setOutput(new NullOutput());
37
        }
38
        return $this->output;
39
    }
40
41
    /**
42
     * @return \Symfony\Component\Console\Output\OutputInterface
43
     */
44
    protected function stderr()
45
    {
46
        $output = $this->output();
47
        if ($output instanceof ConsoleOutputInterface) {
48
            $output = $output->getErrorOutput();
49
        }
50
        return $output;
51
    }
52
53
    /**
54
     * Backwards compatibility
55
     *
56
     * @return \Symfony\Component\Console\Output\OutputInterface
57
     *
58
     * @deprecated
59
     */
60
    protected function getOutput()
61
    {
62
        return $this->output();
63
    }
64
}
65