EnvService   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 25 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 12
loc 48
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A perform() 12 12 2
A old() 0 4 1
A escape() 0 8 2

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
namespace Zoutapps\Laravel\Backpack\Branding\Services;
4
5
use Illuminate\Support\Collection;
6
use Zoutapps\Laravel\Backpack\Branding\Commands\BrandingCommand;
7
use Zoutapps\Laravel\Backpack\Branding\Traits\ValueReplacerTrait;
8
9
class EnvService
10
{
11
    use ValueReplacerTrait;
12
13
    private $command;
14
15
    private $keys = [
0 ignored issues
show
Unused Code introduced by
The property $keys is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
16
        "APP_NAME",
17
        "APP_URL",
18
        "BACKPACK_LICENSE",
19
        "BACKPACK_REGISTRATION_OPEN",
20
    ];
21
22
    public function __construct(BrandingCommand $command, $env)
23
    {
24
        $this->command = $command;
25
        $this->file = $env;
26
        $this->appends = true;
27
        $this->defaults = $this->command->getDefaults('env');
28
    }
29
30 View Code Duplication
    public function perform()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
31
    {
32
        if (file_exists($this->file) === false) {
33
            $this->command->error('You don\'t have a <comment>.env</comment> file.');
34
            return false;
35
        }
36
37
        $this->command->info('Values for <comment>.env</comment>');
38
        $this->applyValues();
39
40
        return true;
41
    }
42
43
    protected function old($key)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
44
    {
45
        return $this->escape(env($key));
46
    }
47
48
    protected function escape($value)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
49
    {
50
        if (str_contains($value, ' ')) {
51
            return '"' . $value . '"';
52
        }
53
54
        return $value;
55
    }
56
}