StartCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 14
rs 9.4285
1
<?php
2
namespace Sovereign\Command;
3
4
use Sovereign\Service\SystemPluginServiceProvider;
5
use Sovereign\Sovereign;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class StartCommand extends Command
12
{
13
    protected function configure()
14
    {
15
        $this
16
            ->setName('start')
17
            ->setDescription('Launch the sovereign bot')
18
            ->addOption(
19
                'configFile',
20
                null,
21
                InputOption::VALUE_OPTIONAL,
22
                'The config php file to load',
23
                'config/config.php'
24
            )
25
        ;
26
    }
27
28
    protected function execute(InputInterface $input, OutputInterface $output)
29
    {
30
        // Use all the memory
31
        ini_set('memory_limit', '-1');
32
        gc_enable();
33
        error_reporting(1);
34
        error_reporting(E_ALL);
35
        define('DISCORDPHP_STARTTIME', microtime(true));
36
        define('BASEDIR', __DIR__);
37
        define('SOVEREIGN_CONFIG_FILE',  realpath('./' . ltrim($input->getOption('configFile'), '/')));
38
39
        // Init the container object
40
        $container = getContainer();
41
42
        // Load the bot into the service container
43
        $container->share('app', Sovereign::class)->withArgument($container);
44
45
        try {
46
            // Init the bot
47
            $container->get('log')->addInfo('Sovereign is starting up..');
48
            $bot = $container->get('app');
49
50
            // Register the default plugins and services, and boot them.
51
            $container->addServiceProvider(SystemPluginServiceProvider::class);
52
        } catch (\Exception $e) {
53
            $container->get('log')->addError('An error occurred: ' . $e->getMessage());
54
            die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method execute() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
55
        }
56
57
        // Launch the bot
58
        $bot->run();
59
    }
60
}
61
62