ConsoleApplication::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.5923

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 4
eloc 11
c 3
b 0
f 0
nc 5
nop 1
dl 0
loc 22
ccs 8
cts 12
cp 0.6667
crap 4.5923
rs 9.9
1
<?php declare(strict_types = 1);
2
3
/**
4
 * This file is part of the Simplex package.
5
 *
6
 * (c) Freddie Frantzen <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Simplex;
12
13
use Psr\Container\ContainerInterface;
14
use Symfony\Component\Console\Application;
15
use Symfony\Component\Console\Command\Command;
16
17
class ConsoleApplication
18
{
19
    /** @var Application */
20
    private $symfonyApplication;
21
22 1
    public function __construct(ContainerInterface $container)
23
    {
24 1
        if (!$container->has(ContainerKeys::CONSOLE_COMMANDS)) {
25
            $this->symfonyApplication = new Application();
26
            return;
27
        }
28
29 1
        $application = new Application();
30
31 1
        if ($container->has(ContainerKeys::CONSOLE_HELPER_SET)) {
32
            $helperSet = $container->get(ContainerKeys::CONSOLE_HELPER_SET);
33
            $application->setHelperSet($helperSet);
34
        }
35
36 1
        $commands = $container->get(ContainerKeys::CONSOLE_COMMANDS);
37
38
        /** @var Command $command */
39 1
        foreach ($commands as $command) {
40 1
            $application->add($command);
41
        }
42
43 1
        $this->symfonyApplication = $application;
44 1
    }
45
46
    public function run(): void
47
    {
48
        $this->symfonyApplication->run();
49
    }
50
51 1
    public function getSymfonyApplication(): Application
52
    {
53 1
        return $this->symfonyApplication;
54
    }
55
}
56