Passed
Branch develop (1ecfd6)
by Nuno
02:37
created

InstallCommand::handle()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5.7629

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 11
cts 16
cp 0.6875
rs 9.1288
c 0
b 0
f 0
cc 5
nc 4
nop 0
crap 5.7629
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\App;
15
16
use LaravelZero\Framework\Components;
17
use LaravelZero\Framework\Commands\Command;
18
use PhpSchool\CliMenu\Terminal\TerminalFactory;
19
use Symfony\Component\Console\Input\ArrayInput;
20
21
final class InstallCommand extends Command
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    protected $signature = 'app:install {component? : The component name}';
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected $description = 'Installs a new component';
32
33
    /**
34
     * The list of components installers.
35
     *
36
     * @var array
37
     */
38
    private $components = [
39
        'console-dusk' => Components\ConsoleDusk\Installer::class,
40
        'database' => Components\Database\Installer::class,
41
        'dotenv' => Components\Dotenv\Installer::class,
42
        'log' => Components\Log\Installer::class,
43
    ];
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 7
    public function handle(): void
49
    {
50 7
        $title = 'Laravel Zero - Component installer';
51
52
        $choices = [
53 7
            'console-dusk' => 'Console Dusk - Laravel Dusk on artisan commands',
54
            'database' => 'Database     - Laravel Eloquent',
55
            'dotenv' => 'Dotenv       - Loads environment variables from `.env`',
56
            'log' => 'Log          - Laravel Log component',
57
        ];
58
59 7
        if (! TerminalFactory::fromSystem()
60 7
            ->isTTY()) {
61
            $option = $this->choice($title, $choices);
62
        } else {
63 7
            $option = $this->argument('component') ?: $this->menu(
0 ignored issues
show
Bug introduced by
The method menu() does not exist on LaravelZero\Framework\Commands\App\InstallCommand. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
            $option = $this->argument('component') ?: $this->/** @scrutinizer ignore-call */ menu(
Loading history...
64
                $title,
65
                $choices
66
            )
67
                ->setForegroundColour('green')
68
                ->setBackgroundColour('black')
69 7
                ->open();
70
        }
71
72 7
        if ($option !== null && ! empty($this->components[$option])) {
73 7
            $command = tap($this->app[$this->components[$option]])->setLaravel($this->app);
74
75 7
            $this->info("Installing {$option} component...");
76
77 7
            $command->run(new ArrayInput([]), $this->output);
78
        }
79 7
    }
80
}
81