Code Duplication    Length = 54-54 lines in 2 locations

src/Checks/ExampleEnvironmentVariablesAreSet.php 1 location

@@ 8-61 (lines=54) @@
5
use Dotenv\Dotenv;
6
use Illuminate\Support\Collection;
7
8
class ExampleEnvironmentVariablesAreSet implements Check
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_set.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
        if (interface_exists(\Dotenv\Environment\FactoryInterface::class)) {
33
            $examples = Dotenv::create(base_path(), '.env.example');
34
            $actual = Dotenv::create(base_path(), '.env');
35
        } else {
36
            $examples = new Dotenv(base_path(), '.env.example');
37
            $actual = new Dotenv(base_path(), '.env');
38
        }
39
40
        $examples->safeLoad();
41
        $actual->safeLoad();
42
43
        $this->envVariables = Collection::make($examples->getEnvironmentVariableNames())
44
            ->diff($actual->getEnvironmentVariableNames());
45
46
        return $this->envVariables->isEmpty();
47
    }
48
49
    /**
50
     * The error message to display in case the check does not pass.
51
     *
52
     * @param array $config
53
     * @return string
54
     */
55
    public function message(array $config): string
56
    {
57
        return trans('self-diagnosis::checks.example_environment_variables_are_set.message', [
58
            'variables' => $this->envVariables->implode(PHP_EOL),
59
        ]);
60
    }
61
}
62

src/Checks/ExampleEnvironmentVariablesAreUpToDate.php 1 location

@@ 8-61 (lines=54) @@
5
use Dotenv\Dotenv;
6
use Illuminate\Support\Collection;
7
8
class ExampleEnvironmentVariablesAreUpToDate implements Check
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
        if (interface_exists(\Dotenv\Environment\FactoryInterface::class)) {
33
            $examples = Dotenv::create(base_path(), '.env.example');
34
            $actual = Dotenv::create(base_path(), '.env');
35
        } else {
36
            $examples = new Dotenv(base_path(), '.env.example');
37
            $actual = new Dotenv(base_path(), '.env');
38
        }
39
40
        $examples->safeLoad();
41
        $actual->safeLoad();
42
43
        $this->envVariables = Collection::make($actual->getEnvironmentVariableNames())
44
            ->diff($examples->getEnvironmentVariableNames());
45
46
        return $this->envVariables->isEmpty();
47
    }
48
49
    /**
50
     * The error message to display in case the check does not pass.
51
     *
52
     * @param array $config
53
     * @return string
54
     */
55
    public function message(array $config): string
56
    {
57
        return trans('self-diagnosis::checks.example_environment_variables_are_up_to_date.message', [
58
            'variables' => $this->envVariables->implode(PHP_EOL),
59
        ]);
60
    }
61
}
62