Completed
Pull Request — master (#50)
by
unknown
01:52
created

ExampleEnvironmentVariablesAreUpToDate   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 49
loc 49
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
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 ExampleEnvironmentVariablesAreUpToDate 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
     * The name of the check.
15
     *
16
     * @param array $config
17
     * @return string
18
     */
19
    public function name(array $config): string
20
    {
21
        return trans('self-diagnosis::checks.example_environment_variables_are_up_to_date.name');
22
    }
23
24
    /**
25
     * Perform the actual verification of this check.
26
     *
27
     * @param array $config
28
     * @return bool
29
     */
30
    public function check(array $config): bool
31
    {
32
        $examples = new Dotenv(base_path(), '.env.example');
33
        $examples->safeLoad();
34
35
        $actual = new Dotenv(base_path(), '.env');
36
        $actual->safeLoad();
37
38
        $this->envVariables = Collection::make($actual->getEnvironmentVariableNames())
39
            ->diff($examples->getEnvironmentVariableNames());
40
41
        return $this->envVariables->isEmpty();
42
    }
43
44
    /**
45
     * The error message to display in case the check does not pass.
46
     *
47
     * @param array $config
48
     * @return string
49
     */
50
    public function message(array $config): string
51
    {
52
        return trans('self-diagnosis::checks.example_environment_variables_are_up_to_date.message', [
53
            'variables' => $this->envVariables->implode(PHP_EOL),
54
        ]);
55
    }
56
}
57