CommandsBootstrapper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 1
b 0
f 0
dl 0
loc 24
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A registerBindings() 0 18 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Admin\Bootstrappers\Console\Commands;
6
7
use Exception;
8
use Opulence\Console\Commands\CommandCollection;
9
use Opulence\Framework\Configuration\Config;
10
use Opulence\Ioc\Bootstrappers\Bootstrapper;
11
use Opulence\Ioc\IContainer;
12
use Opulence\Ioc\IocException;
13
use RuntimeException;
14
15
/**
16
 * Defines the command bootstrapper
17
 */
18
class CommandsBootstrapper extends Bootstrapper
19
{
20
    /**
21
     * @inheritdoc
22
     * @throws IocException
23
     */
24
    public function registerBindings(IContainer $container)
25
    {
26
        global $abterModuleManager;
27
28
        $commands = $container->resolve(CommandCollection::class);
29
        $globalCommandClasses = require Config::get('paths', 'config.console') . '/commands.php';
30
31
        $abterCommandClasses = $abterModuleManager->getCommands();
32
33
        $commandClasses = array_merge($globalCommandClasses, $abterCommandClasses);
34
35
        try {
36
            // Instantiate each command class
37
            foreach ($commandClasses as $commandClass) {
38
                $commands->add($container->resolve($commandClass));
39
            }
40
        } catch (Exception $ex) {
41
            throw new RuntimeException('Failed to add console commands', 0, $ex);
42
        }
43
    }
44
}
45