ConsoleApplicationFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 1
b 0
f 0
dl 0
loc 23
rs 10
ccs 11
cts 11
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 8 1
A __construct() 0 4 1
A registerCommands() 0 5 2
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