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

AbstractInstaller   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 58
ccs 15
cts 15
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A handle() 0 4 1
A require() 0 11 1
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\Components;
13
14
use Illuminate\Filesystem\Filesystem;
15
use LaravelZero\Framework\Commands\Command;
16
use LaravelZero\Framework\Contracts\Commands\Component\Installer;
17
use LaravelZero\Framework\Contracts\Providers\Composer as ComposerContract;
18
19
/**
20
 * This is the Laravel Zero Framework Abstract Installer Implementation.
21
 */
22
abstract class AbstractInstaller extends Command implements Installer
23
{
24
    /**
25
     * Holds an instance of Files.
26
     *
27
     * @var \Illuminate\Filesystem\Filesystem
28
     */
29
    protected $files;
30
31
    /**
32
     * Holds an instance of composer.
33
     *
34
     * @var \LaravelZero\Framework\Contracts\Providers\Composer
35
     */
36
    protected $composer;
37
38
    /**
39
     * Installer constructor.
40
     *
41
     * @param \Illuminate\Filesystem\Filesystem $files
42
     * @param \LaravelZero\Framework\Contracts\Providers\Composer $composer
43
     */
44 6
    public function __construct(Filesystem $files, ComposerContract $composer)
45
    {
46 6
        parent::__construct();
47
48 6
        $this->files = $files;
49
50 6
        $this->composer = $composer;
51 6
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 6
    public function handle(): void
57
    {
58 6
        $this->install();
59 6
    }
60
61
    /**
62
     * Requires the provided package.
63
     *
64
     * @param  string $package
65
     *
66
     * @return \LaravelZero\Framework\Contracts\Commands\Component\Installer
67
     */
68 6
    protected function require(string $package): Installer
69
    {
70 6
        $this->task(
0 ignored issues
show
Documentation Bug introduced by
The method task does not exist on object<LaravelZero\Frame...ents\AbstractInstaller>? 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...
71 6
            'Require package via composer',
72 6
            function () use ($package) {
73 6
                return $this->composer->require($package);
74 6
            }
75
        );
76
77 6
        return $this;
78
    }
79
}
80