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

Installer::install()   B

Complexity

Conditions 5
Paths 1

Size

Total Lines 40
Code Lines 23

Duplication

Lines 27
Ratio 67.5 %

Code Coverage

Tests 20
CRAP Score 5.4358

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 27
loc 40
ccs 20
cts 27
cp 0.7407
rs 8.439
cc 5
eloc 23
nc 1
nop 0
crap 5.4358
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\Dotenv;
13
14
use Illuminate\Support\Str;
15
use Illuminate\Support\Facades\File;
16
use LaravelZero\Framework\Components\AbstractInstaller;
17
18
/**
19
 * This is the Laravel Zero Framework Dot Env Component Installer Implementation.
20
 */
21
class Installer extends AbstractInstaller
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    protected $name = 'install:dotenv';
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected $description = 'Installs vlucas/phpdotenv';
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 2
    public function install(): void
37
    {
38 2
        $this->require('vlucas/phpdotenv');
39
40 2
        $this->task(
0 ignored issues
show
Documentation Bug introduced by
The method task does not exist on object<LaravelZero\Frame...nents\Dotenv\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...
41 2
            'Creating .env',
42 2 View Code Duplication
            function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43 2
                if (! File::exists(base_path('.env'))) {
44 2
                    return File::put(base_path('.env'), 'CONSUMER_KEY=');
45
                }
46
47
                return false;
48 2
            }
49
        );
50
51 2
        $this->task(
0 ignored issues
show
Documentation Bug introduced by
The method task does not exist on object<LaravelZero\Frame...nents\Dotenv\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...
52 2
            'Creating .env.example',
53 2 View Code Duplication
            function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54 2
                if (! File::exists(base_path('.env.example'))) {
55 2
                    return File::put(base_path('.env.example'), 'CONSUMER_KEY=');
56
                }
57
58
                return false;
59 2
            }
60
        );
61
62 2 View Code Duplication
        $this->task('Updating .gitignore', function () {
0 ignored issues
show
Documentation Bug introduced by
The method task does not exist on object<LaravelZero\Frame...nents\Dotenv\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...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63 2
            $gitignorePath = base_path('.gitignore');
64 2
            if (File::exists($gitignorePath)) {
65
                $contents = File::get($gitignorePath);
66
                $neededLine = '.env';
67
                if (! Str::contains($contents, $neededLine)) {
68
                    File::append($gitignorePath, $neededLine . PHP_EOL);
69
                    return true;
70
                }
71
            }
72
73 2
            return false;
74 2
        });
75 2
    }
76
}
77