InstallCommand::handle()   A
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5.0144

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 11
c 3
b 1
f 0
dl 0
loc 21
rs 9.6111
ccs 11
cts 12
cp 0.9167
cc 5
nc 8
nop 0
crap 5.0144
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Laravel Zero.
7
 *
8
 * (c) Nuno Maduro <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace LaravelZero\Framework\Commands;
15
16
use LaravelZero\Framework\Components;
17
use Symfony\Component\Console\Input\ArrayInput;
18
19
final class InstallCommand extends Command
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    protected $signature = 'app:install {component? : The component name}';
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    protected $description = 'Install optional components';
30
31
    /**
32
     * The list of components installers.
33
     *
34
     * @var array
35
     */
36
    private $components = [
37
        'console-dusk' => Components\ConsoleDusk\Installer::class,
38
        'database' => Components\Database\Installer::class,
39
        'dotenv' => Components\Dotenv\Installer::class,
40
        'log' => Components\Log\Installer::class,
41
        'logo' => Components\Logo\Installer::class,
42
        'menu' => Components\Menu\Installer::class,
43
        'queue' => Components\Queue\Installer::class,
44
        'schedule-list' => Components\ScheduleList\Installer::class,
45
        'self-update' => Components\Updater\Installer::class,
46
    ];
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 14
    public function handle()
52
    {
53 14
        $title = 'Laravel Zero - Component installer';
54
55 14
        $choices = [];
56 14
        foreach ($this->components as $name => $componentClass) {
57 14
            $choices[$name] = $this->app->make($componentClass)->getDescription();
58
        }
59
60 14
        if (! $option = $this->argument('component')) {
61
            $option = $this->choice($title, $choices);
62
        }
63
64 14
        if ($option !== null && ! empty($this->components[$option])) {
65 14
            $command = tap($this->app[$this->components[$option]])->setLaravel($this->app);
66
67 14
            $command->setApplication($this->getApplication());
68
69 14
            $this->info("Installing {$option} component...");
70
71 14
            $command->run(new ArrayInput([]), $this->output);
72
        }
73 14
    }
74
}
75