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

Installer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 48.21 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 74.07%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 0
cbo 2
dl 27
loc 56
ccs 20
cts 27
cp 0.7407
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B install() 27 40 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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