Test Failed
Push — stable ( 2c3eb1...1dab66 )
by Nuno
05:39
created

Configurations   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 65
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
C bootstrap() 0 38 7
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 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 Configurations 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
        if ($name = $config->get('app.name')) {
49
            $this->application->setName($name);
50
        }
51
52
        if ($version = $config->get('app.version')) {
53
            $this->application->setVersion($version);
54
        }
55
56
        $commands = collect(
57
            array_merge(
58
                $config->get('app.commands') ?: [],
59
                $this->commands
60
            )
61
        );
62
63
        if (! $config->get('app.production')) {
64
            $commands = $commands->merge($this->developmentCommands);
65
        }
66
67
        $commands->push($config->get('app.default-command'))
68
            ->each(
69
                function ($command) {
70
                    if ($command) {
71
                        $commandInstance = $this->container->make($command);
72
73
                        if ($commandInstance instanceof Commands\Command) {
74
                            $this->container->call([$commandInstance, 'schedule']);
75
                        }
76
77
                        $this->application->add($commandInstance);
78
                    }
79
                }
80
            );
81
    }
82
}
83