Completed
Push — stable ( 86ecc3...3a45ea )
by Nuno
07:34
created

Installer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 49
ccs 8
cts 12
cp 0.6667
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 22 4
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 Symfony\Component\Console\Input\ArrayInput;
17
18
/**
19
 * This is the Laravel Zero Framework Installer Command implementation.
20
 */
21
class Installer 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
    protected $components = [
39
        'database' => Components\Database\Installer::class,
40
        'dotenv' => Components\Dotenv\Installer::class,
41
        'log' => Components\Log\Installer::class,
42
    ];
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 6
    public function handle(): void
48
    {
49 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...
50
            'Laravel Zero - Component installer',
51
            [
52
                'database' =>   'Database - Laravel Eloquent',
53
                'log' =>        'Log      - Laravel Log component',
54
                'dotenv' =>     'Dotenv   - Loads environment variables from `.env`',
55
            ]
56
        )
57
            ->setForegroundColour('green')
58
            ->setBackgroundColour('black')
59 6
            ->open();
60
61 6
        if ($option !== null && ! empty($this->components[$option])) {
62 6
            ($command = $this->app[$this->components[$option]])->setLaravel($this->app);
63
64 6
            $this->info("Installing {$option} component...");
65
66 6
            $command->run(new ArrayInput([]), $this->output);
67
        }
68 6
    }
69
}
70