Passed
Push — stable ( 7698e0...f9d7ca )
by Nuno
03:02
created

Installer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 65
ccs 20
cts 20
cp 1
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 47
    public function __construct(Filesystem $files, ComposerContract $composer)
38
    {
39 47
        parent::__construct();
40
41 47
        $this->files = $files;
42
43 47
        $this->composer = $composer;
44 47
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 4
    public function handle(): void
50
    {
51 4
        $component = $this->getComponentName();
52
53 4
        $this->task(
54 4
            "The component $component database installation",
55 4
            function () {
56 4
                return $this->install();
57 4
            }
58
        );
59 4
    }
60
61
    /**
62
     * Requires the provided package.
63
     *
64
     * @param  string $package
65
     *
66
     * @return \LaravelZero\Framework\Contracts\Commands\Component\Installer
67
     */
68 4
    protected function require(string $package): InstallerContract
69
    {
70 4
        $this->task(
71 4
            "Pulling $package...",
72 4
            function () use ($package) {
73 4
                return $this->composer->require($package);
74 4
            }
75
        );
76
77 4
        return $this;
78
    }
79
}
80