Test Setup Failed
Push — master ( 016bc5...505cdc )
by Alec
02:25
created

SymfonyOutputAdapter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 4
eloc 11
c 3
b 0
f 1
dl 0
loc 34
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A getStream() 0 3 1
A write() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Spinner\Core\Adapters;
4
5
use AlecRabbit\Spinner\Core\Contracts\OutputInterface;
6
use Symfony\Component\Console\Output\ConsoleOutput;
7
use Symfony\Component\Console\Output\StreamOutput;
8
use function AlecRabbit\typeOf;
9
10
/**
11
 * Class SymfonyOutputAdapter
12
 *
13
 * @codeCoverageIgnore
14
 */
15
class SymfonyOutputAdapter implements OutputInterface
16
{
17
    /** @var StreamOutput */
18
    protected $output;
19
20
    public function __construct(ConsoleOutput $output)
21
    {
22
        $streamOutput = $output->getErrorOutput();
23
        if ($streamOutput instanceof StreamOutput) {
0 ignored issues
show
introduced by
$streamOutput is always a sub-type of Symfony\Component\Console\Output\StreamOutput.
Loading history...
24
            $this->output = $streamOutput;
25
        } else {
26
            // @codeCoverageIgnoreStart
27
            throw new \RuntimeException(
28
                'Should never happen. $streamOutput is of wrong type: [' .
29
                StreamOutput::class . '] expected , ['
30
                . typeOf($streamOutput) . '] given.'
31
            );
32
            // @codeCoverageIgnoreEnd
33
        }
34
35
    }
0 ignored issues
show
Coding Style introduced by
Function closing brace must go on the next line following the body; found 1 blank lines before brace
Loading history...
36
37
    /** {@inheritDoc} */
38
    public function write($messages, $newline = false, $options = 0): void
39
    {
40
        $this->output->write($messages, $newline, $options);
41
    }
42
43
    /**
44
     * @return resource
45
     */
46
    public function getStream()
47
    {
48
        return $this->output->getStream();
49
    }
50
}
51