Completed
Pull Request — master (#60)
by
unknown
177:15
created

ExampleEnvironmentVariablesAreSet   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 57
loc 57
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A name() 4 4 1
A check() 13 13 1
A message() 6 6 1

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 BeyondCode\SelfDiagnosis\Checks;
4
5
use Dotenv\Dotenv;
6
use Illuminate\Support\Collection;
7
8 View Code Duplication
class ExampleEnvironmentVariablesAreSet implements Check
0 ignored issues
show
Duplication introduced by
This class 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...
9
{
10
    /** @var Collection */
11
    private $envVariables;
12
13
    /**
14
     * Construct the check, pre set the private variable.
15
     */
16 12
    public function __construct()
17
    {
18 12
        $this->envVariables = new Collection();
19 12
    }
20
21
    /**
22
     * The name of the check.
23
     *
24
     * @param array $config
25
     * @return string
26
     */
27 4
    public function name(array $config): string
28
    {
29 4
        return trans('self-diagnosis::checks.example_environment_variables_are_set.name');
30
    }
31
32
    /**
33
     * Perform the actual verification of this check.
34
     *
35
     * @param array $config
36
     * @return bool
37
     */
38 4
    public function check(array $config): bool
39
    {
40 4
        $examples = new Dotenv(base_path(), '.env.example');
41 4
        $examples->safeLoad();
42
43 4
        $actual = new Dotenv(base_path(), '.env');
44 4
        $actual->safeLoad();
45
46 4
        $this->envVariables = Collection::make($examples->getEnvironmentVariableNames())
47 4
            ->diff($actual->getEnvironmentVariableNames());
48
49 4
        return $this->envVariables->isEmpty();
50
    }
51
52
    /**
53
     * The error message to display in case the check does not pass.
54
     *
55
     * @param array $config
56
     * @return string
57
     */
58 8
    public function message(array $config): string
59
    {
60 8
        return trans('self-diagnosis::checks.example_environment_variables_are_set.message', [
61 8
            'variables' => $this->envVariables->implode(PHP_EOL),
62
        ]);
63
    }
64
}
65