AbstractInstaller   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 13
dl 0
loc 54
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 3 1
A __construct() 0 7 1
A require() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Laravel Zero.
7
 *
8
 * (c) Nuno Maduro <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace LaravelZero\Framework\Components;
15
16
use Illuminate\Filesystem\Filesystem;
17
use LaravelZero\Framework\Commands\Command;
18
use LaravelZero\Framework\Contracts\Commands\Component\InstallerContract;
19
use LaravelZero\Framework\Contracts\Providers\ComposerContract;
20
21
/**
22
 * @internal
23
 */
24
abstract class AbstractInstaller extends Command implements InstallerContract
25
{
26
    /**
27
     * Holds an instance of Files.
28
     *
29
     * @var \Illuminate\Filesystem\Filesystem
30
     */
31
    protected $files;
32
33
    /**
34
     * Holds an instance of composer.
35
     *
36
     * @var \LaravelZero\Framework\Contracts\Providers\ComposerContract
37
     */
38
    protected $composer;
39
40
    /**
41
     * AbstractInstaller constructor.
42
     */
43 14
    public function __construct(Filesystem $files, ComposerContract $composer)
44
    {
45 14
        parent::__construct();
46
47 14
        $this->files = $files;
48
49 14
        $this->composer = $composer;
50 14
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 14
    public function handle()
56
    {
57 14
        $this->install();
58 14
    }
59
60
    /**
61
     * Requires the provided package.
62
     *
63
     * @param  string $package
64
     * @param  bool $dev
65
     *
66
     * @return \LaravelZero\Framework\Contracts\Commands\Component\InstallerContract
67
     */
68 12
    protected function require(string $package, bool $dev = false): InstallerContract
69
    {
70 12
        $this->task(
71 12
            'Require package via composer',
72
            function () use ($package, $dev) {
73 12
                return $this->composer->require($package, $dev);
74 12
            }
75
        );
76
77 12
        return $this;
78
    }
79
}
80