Passed
Pull Request — master (#13)
by Evgeniy
10:53
created

ConsoleApplicationRunner::withContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Runner\Console;
6
7
use ErrorException;
8
use Exception;
9
use Psr\Container\ContainerExceptionInterface;
10
use Psr\Container\ContainerInterface;
11
use Psr\Container\NotFoundExceptionInterface;
12
use Throwable;
13
use Yiisoft\Definitions\Exception\CircularReferenceException;
14
use Yiisoft\Definitions\Exception\InvalidConfigException;
15
use Yiisoft\Definitions\Exception\NotInstantiableException;
16
use Yiisoft\Di\Container;
17
use Yiisoft\Di\NotFoundException;
18
use Yiisoft\Yii\Console\Application;
19
use Yiisoft\Yii\Console\ExitCode;
20
use Yiisoft\Yii\Console\Output\ConsoleBufferedOutput;
21
use Yiisoft\Yii\Runner\ApplicationRunner;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Yii\Runner\ApplicationRunner was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
23
/**
24
 * `ConsoleApplicationRunner` runs the Yii console application.
25
 */
26
final class ConsoleApplicationRunner extends ApplicationRunner
27
{
28
    /**
29
     * @param string $rootPath The absolute path to the project root.
30
     * @param bool $debug Whether the debug mode is enabled.
31
     * @param string|null $environment The environment name.
32
     */
33
    public function __construct(string $rootPath, bool $debug, ?string $environment)
34
    {
35
        parent::__construct($rootPath, $debug, $environment);
36
        $this->bootstrapGroup = 'bootstrap-console';
0 ignored issues
show
Bug Best Practice introduced by
The property bootstrapGroup does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
37
        $this->eventsGroup = 'events-console';
0 ignored issues
show
Bug Best Practice introduced by
The property eventsGroup does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
38
    }
39
40
    /**
41
     * {@inheritDoc}
42
     *
43
     * @throws CircularReferenceException|ErrorException|Exception|InvalidConfigException
44
     * @throws ContainerExceptionInterface|NotFoundException|NotFoundExceptionInterface|NotInstantiableException
45
     */
46
    public function run(): void
47
    {
48
        $config = $this->config ?? $this->createConfig();
49
        $container = $this->container ?? $this->createContainer($config, 'console');
50
51
        if ($container instanceof Container) {
52
            $container = $container->get(ContainerInterface::class);
53
        }
54
55
        $this->runBootstrap($config, $container);
56
        $this->checkEvents($config, $container);
57
58
        /** @var Application */
59
        $application = $container->get(Application::class);
60
        $exitCode = ExitCode::UNSPECIFIED_ERROR;
61
62
        try {
63
            $application->start();
64
            $exitCode = $application->run(null, new ConsoleBufferedOutput());
65
        } catch (Throwable $throwable) {
66
            $application->renderThrowable($throwable, new ConsoleBufferedOutput());
67
        } finally {
68
            $application->shutdown($exitCode);
69
            exit($exitCode);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
70
        }
71
    }
72
}
73