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

ExampleEnvironmentVariablesAreSet::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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