Test Failed
Push — stable ( 994ca0...7d5c83 )
by Nuno
04:30
created

InstallCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 72.21%

Importance

Changes 0
Metric Value
wmc 6
eloc 27
dl 0
loc 57
ccs 13
cts 18
cp 0.7221
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 29 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 = 'Installs a new component';
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
        'queue' => Components\Queue\Installer::class,
43
    ];
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 10
    public function handle()
49
    {
50 10
        $title = 'Laravel Zero - Component installer';
51
52 10
        $choices = [];
53 10
        foreach ($this->components as $name => $componentClass) {
54 10
            $choices[$name] = $this->app->make($componentClass)->getDescription();
55
        }
56
57 10
        if (! Process::isTtySupported()) {
58
            $option = $this->choice($title, $choices);
59
        } else {
60 10
            $option = $this->argument('component') ?: $this->menu(
61
                $title,
62
                $choices
63
            )
64
                ->setForegroundColour('green')
65
                ->setBackgroundColour('black')
66 10
                ->open();
67
        }
68
69 10
        if ($option !== null && ! empty($this->components[$option])) {
70 10
            $command = tap($this->app[$this->components[$option]])->setLaravel($this->app);
71
72 10
            $command->setApplication($this->getApplication());
73
74 10
            $this->info("Installing {$option} component...");
75
76 10
            $command->run(new ArrayInput([]), $this->output);
77
        }
78 10
    }
79
}
80