Passed
Push — stable ( 0052be...39bea3 )
by Nuno
01:59
created

InstallCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 81.25%

Importance

Changes 0
Metric Value
wmc 6
eloc 26
dl 0
loc 56
ccs 13
cts 16
cp 0.8125
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 27 6
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\Process\Process;
18
use Symfony\Component\Console\Input\ArrayInput;
19
20
final class InstallCommand extends Command
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    protected $signature = 'app:install {component? : The component name}';
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected $description = 'Install optional components';
31
32
    /**
33
     * The list of components installers.
34
     *
35
     * @var array
36
     */
37
    private $components = [
38
        'console-dusk' => Components\ConsoleDusk\Installer::class,
39
        'database' => Components\Database\Installer::class,
40
        'dotenv' => Components\Dotenv\Installer::class,
41
        'log' => Components\Log\Installer::class,
42
        'logo' => Components\Logo\Installer::class,
43
        'queue' => Components\Queue\Installer::class,
44
    ];
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 12
    public function handle()
50
    {
51 12
        $title = 'Laravel Zero - Component installer';
52
53 12
        $choices = [];
54 12
        foreach ($this->components as $name => $componentClass) {
55 12
            $choices[$name] = $this->app->make($componentClass)->getDescription();
56
        }
57
58 12
        if (! Process::isTtySupported()) {
59
            $option = $this->choice($title, $choices);
60
        } else {
61 12
            $option = $this->argument('component') ?: $this->menu(
62
                $title,
63
                $choices
64
            )
65 12
                ->open();
66
        }
67
68 12
        if ($option !== null && ! empty($this->components[$option])) {
69 12
            $command = tap($this->app[$this->components[$option]])->setLaravel($this->app);
70
71 12
            $command->setApplication($this->getApplication());
72
73 12
            $this->info("Installing {$option} component...");
74
75 12
            $command->run(new ArrayInput([]), $this->output);
76
        }
77 12
    }
78
}
79