Passed
Push — stable ( 4d156d...ebeda6 )
by Nuno
02:33
created

Installer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 68.75%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 58
ccs 11
cts 16
cp 0.6875
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 31 5
1
<?php
2
3
/**
4
 * This file is part of Laravel Zero.
5
 *
6
 * (c) Nuno Maduro <[email protected]>
7
 *
8
 *  For the full copyright and license information, please view the LICENSE
9
 *  file that was distributed with this source code.
10
 */
11
12
namespace LaravelZero\Framework\Commands\App;
13
14
use LaravelZero\Framework\Components;
15
use LaravelZero\Framework\Commands\Command;
16
use PhpSchool\CliMenu\Terminal\TerminalFactory;
17
use Symfony\Component\Console\Input\ArrayInput;
18
19
/**
20
 * This is the Laravel Zero Framework Installer Command implementation.
21
 */
22
class Installer extends Command
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected $signature = 'app:install {component? : The component name}';
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    protected $description = 'Installs a new component';
33
34
    /**
35
     * The list of components installers.
36
     *
37
     * @var array
38
     */
39
    protected $components = [
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 6
    public function handle(): void
49
    {
50 6
        $title = 'Laravel Zero - Component installer';
51
52
        $choices = [
53 6
            'database' =>   'Database - Laravel Eloquent',
54
            'log' =>        'Log      - Laravel Log component',
55
            'dotenv' =>     'Dotenv   - Loads environment variables from `.env`',
56
        ];
57
58 6
        if (! TerminalFactory::fromSystem()->isTTY()) {
59
            $option = $this->choice($title, $choices);
60
        } else {
61 6
            $option = $this->argument('component') ?: $this->menu(
0 ignored issues
show
Documentation Bug introduced by
The method menu does not exist on object<LaravelZero\Frame...Commands\App\Installer>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
62
                $title,
63
                $choices
64
            )->setForegroundColour('green')
65
                ->setBackgroundColour('black')
66 6
                ->open();
67
        }
68
69
70
71 6
        if ($option !== null && ! empty($this->components[$option])) {
72 6
            ($command = $this->app[$this->components[$option]])->setLaravel($this->app);
73
74 6
            $this->info("Installing {$option} component...");
75
76 6
            $command->run(new ArrayInput([]), $this->output);
77
        }
78 6
    }
79
}
80