Test Failed
Push — stable ( 977f63...62e79c )
by Nuno
02:59
created

Installer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 65
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A handle() 0 11 1
A require() 0 11 1
1
<?php
2
3
namespace LaravelZero\Framework\Commands\Component;
4
5
use Illuminate\Filesystem\Filesystem;
6
use LaravelZero\Framework\Commands\Command;
7
use LaravelZero\Framework\Contracts\Providers\Composer as ComposerContract;
8
use LaravelZero\Framework\Contracts\Commands\Component\Installer as InstallerContract;
9
10
/**
11
 * This is the Laravel Zero Framework component installer command class.
12
 *
13
 * @author Nuno Maduro <[email protected]>
14
 */
15
abstract class Installer extends Command implements InstallerContract
16
{
17
    /**
18
     * Holds an instance of Files.
19
     *
20
     * @var \Illuminate\Filesystem\Filesystem
21
     */
22
    protected $files;
23
24
    /**
25
     * Holds an instance of composer.
26
     *
27
     * @var \LaravelZero\Framework\Contracts\Providers\Composer
28
     */
29
    protected $composer;
30
31
    /**
32
     * Installer constructor.
33
     *
34
     * @param \Illuminate\Filesystem\Filesystem $files
35
     * @param \LaravelZero\Framework\Contracts\Providers\Composer $composer
36
     */
37
    public function __construct(Filesystem $files, ComposerContract $composer)
38
    {
39
        parent::__construct();
40
41
        $this->files = $files;
42
43
        $this->composer = $composer;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function handle(): void
50
    {
51
        $component = $this->getComponentName();
52
53
        $this->task(
54
            "The component $component database installation",
55
            function () {
56
                return $this->install();
57
            }
58
        );
59
    }
60
61
    /**
62
     * Requires the provided package.
63
     *
64
     * @param  string $package
65
     *
66
     * @return \LaravelZero\Framework\Contracts\Commands\Component\Installer
67
     */
68
    protected function require(string $package): InstallerContract
69
    {
70
        $this->task(
71
            "Pulling $package...",
72
            function () use ($package) {
73
                return $this->composer->require($package);
74
            }
75
        );
76
77
        return $this;
78
    }
79
}
80