hanneskod /
readme-tester
| 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
Loading history...
|
|||
| 30 | } |
||
| 31 | |||
| 32 | public function setOutput(OutputInterface $output): void |
||
| 33 | { |
||
| 34 | $this->output = $output; |
||
| 35 | } |
||
| 36 | } |
||
| 37 |