Test Failed
Push — stable ( a61ff6...01ae3e )
by Nuno
01:52
created

LoadCommands   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 57
rs 10
c 1
b 0
f 0
wmc 5
lcom 1
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B bootstrap() 0 30 5
1
<?php
2
3
namespace LaravelZero\Framework\Bootstrappers;
4
5
use Illuminate\Console\Scheduling;
6
use LaravelZero\Framework\Commands;
7
8
/**
9
 * This is the Laravel Zero Framework Bootstrapper Configuration class.
10
 *
11
 * Configures the console application.
12
 *
13
 * Takes in consideration the app name and the app version. Also
14
 * adds all the application commands.
15
 *
16
 * @author Nuno Maduro <[email protected]>
17
 */
18
class LoadCommands extends Bootstrapper
19
{
20
    /**
21
     * The application's core commands.
22
     *
23
     * @var string[]
24
     */
25
    protected $commands = [
26
        Scheduling\ScheduleRunCommand::class,
27
        Scheduling\ScheduleFinishCommand::class,
28
    ];
29
30
    /**
31
     * The application's development commands.
32
     *
33
     * @var string[]
34
     */
35
    protected $developmentCommands = [
36
        Commands\App\Builder::class,
37
        Commands\App\Renamer::class,
38
        Commands\Component\Installer::class,
39
    ];
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function bootstrap(): void
45
    {
46
        $config = $this->container->make('config');
47
48
        $commands = collect(
49
            array_merge(
50
                $config->get('app.commands') ?: [],
51
                $this->commands
52
            )
53
        );
54
55
        if (! $config->get('app.production')) {
56
            $commands = $commands->merge($this->developmentCommands);
57
        }
58
59
        $commands->push($config->get('app.default-command'))
60
            ->each(
61
                function ($command) {
62
                    if ($command) {
63
                        $commandInstance = $this->container->make($command);
64
65
                        if ($commandInstance instanceof Commands\Command) {
66
                            $this->container->call([$commandInstance, 'schedule']);
67
                        }
68
69
                        $this->application->add($commandInstance);
70
                    }
71
                }
72
            );
73
    }
74
}
75