Passed
Push — master ( 4c2a8d...f1f030 )
by Hannes
02:10
created

AbstractOutputtingSubscriber::getOutput()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace hanneskod\readmetester\Output;
6
7
use hanneskod\readmetester\Event;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
abstract class AbstractOutputtingSubscriber
11
{
12
    private ?OutputInterface $output;
13
14
    public function onErrorEvent(Event\ErrorEvent $event): void
15
    {
16
        $this->getOutput()->writeln("<error>{$event->getMessage()}</error>");
17
18
        if ($this->getOutput()->isVerbose()) {
19
            $this->getOutput()->writeln("<error>{$event->getException()}</error>");
20
        }
21
    }
22
23
    public function getOutput(): OutputInterface
24
    {
25
        if (!isset($this->output)) {
26
            throw new \LogicException('Unable to get output, did you call setOutput()?');
27
        }
28
29
        return $this->output;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->output could return the type null which is incompatible with the type-hinted return Symfony\Component\Console\Output\OutputInterface. Consider adding an additional type-check to rule them out.
Loading history...
30
    }
31
32
    public function setOutput(OutputInterface $output): void
33
    {
34
        $this->output = $output;
35
    }
36
}
37