ConsoleApplicationFactory::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
rs 10
ccs 5
cts 5
cp 1
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 *  This file is part of the Micro framework package.
5
 *
6
 *  (c) Stanislau Komar <[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
12
namespace Micro\Plugin\Console\Business\Factory;
13
14
use Micro\Component\DependencyInjection\Autowire\AutowireHelperInterface;
15
use Micro\Plugin\Locator\Facade\LocatorFacadeInterface;
16
use Symfony\Component\Console\Application;
17
use Symfony\Component\Console\Command\Command;
18
19
class ConsoleApplicationFactory implements ConsoleApplicationFactoryInterface
20
{
21 2
    public function __construct(
22
        private readonly LocatorFacadeInterface $locatorFacade,
23
        private readonly AutowireHelperInterface $autowireHelper
24
    ) {
25 2
    }
26
27 1
    public function create(): Application
28
    {
29 1
        $application = new Application();
30 1
        $application->setAutoExit(false);
31
        // $application->setCatchExceptions(true);
32 1
        $this->registerCommands($application);
33
34 1
        return $application;
35
    }
36
37 1
    protected function registerCommands(Application $application): void
38
    {
39 1
        foreach ($this->locatorFacade->lookup(Command::class) as $command) {
40 1
            $cmdCallback = $this->autowireHelper->autowire($command);
41 1
            $application->add($cmdCallback());
42
        }
43
    }
44
}
45