Passed
Branch develop (0af400)
by Nuno
02:22
created

InstallCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 73.68%

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 58
ccs 14
cts 19
cp 0.7368
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 30 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 PhpSchool\CliMenu\Terminal\TerminalFactory;
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(): void
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();
0 ignored issues
show
Bug introduced by
The method make() does not exist on null. ( Ignorable by Annotation )

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

54
            $choices[$name] = $this->app->/** @scrutinizer ignore-call */ make($componentClass)->getDescription();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
        }
56
57 10
        if (! TerminalFactory::fromSystem()
58 10
            ->isTTY()) {
59
            $option = $this->choice($title, $choices);
60
        } else {
61 10
            $option = $this->argument('component') ?: $this->menu(
0 ignored issues
show
Bug introduced by
The method menu() does not exist on LaravelZero\Framework\Commands\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

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