Passed
Push — master ( 9638a7...1ba969 )
by Alexander
02:32
created

Application::setDispatcher()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Console;
6
7
use Psr\EventDispatcher\EventDispatcherInterface;
8
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as SymfonyEventDispatcherInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Symfony\Component\Console\Style\StyleInterface;
11
use Yiisoft\FriendlyException\FriendlyExceptionInterface;
12
use Yiisoft\Yii\Console\Event\ApplicationShutdown;
13
use Yiisoft\Yii\Console\Event\ApplicationStartup;
14
15
class Application extends \Symfony\Component\Console\Application
16
{
17
    public const VERSION = '3.0.0-dev';
18
19
    private EventDispatcherInterface $dispatcher;
20
21 2
    public function __construct(string $name = 'Yii Console', string $version = self::VERSION)
22
    {
23 2
        parent::__construct($name, $version);
24 2
    }
25
26 2
    public function setDispatcher(SymfonyEventDispatcherInterface $dispatcher): void
27
    {
28 2
        $this->dispatcher = $dispatcher;
29 2
        parent::setDispatcher($dispatcher);
30 2
    }
31
32
    public function getDispatcher(): EventDispatcherInterface
33
    {
34
        return $this->dispatcher;
35
    }
36
37
    public function start(): void
38
    {
39
        $this->dispatcher->dispatch(new ApplicationStartup());
40
    }
41
42
    public function shutdown(int $exitCode): void
43
    {
44
        $this->dispatcher->dispatch(new ApplicationShutdown($exitCode));
45
    }
46
47
    /**
48
     * @suppress PhanUndeclaredStaticMethod
49
     */
50
    public function doRenderException(\Exception $e, OutputInterface $output)
51
    {
52
        parent::doRenderException($e, $output);
0 ignored issues
show
introduced by
The method doRenderException() does not exist on Symfony\Component\Console\Application. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
        parent::/** @scrutinizer ignore-call */ 
53
                doRenderException($e, $output);
Loading history...
53
        // Friendly Exception support
54
        if ($e instanceof FriendlyExceptionInterface) {
55
            if ($output instanceof StyleInterface) {
56
                $output->title($e->getName());
57
                $output->note($e->getSolution());
58
                $output->newLine();
59
            } else {
60
                $output->writeln([
61
                    '<fg=red>' . $e->getName() . '</>',
62
                    '<fg=yellow>' . $e->getSolution() . '</>',
63
                    '',
64
                ]);
65
            }
66
        }
67
    }
68
}
69