Completed
Pull Request — master (#82)
by
unknown
05:39
created

CachePrefixIsSet   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 43
ccs 8
cts 10
cp 0.8
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 4 1
A check() 0 12 2
A message() 0 4 1
1
<?php
2
3
namespace BeyondCode\SelfDiagnosis\Checks;
4
5
use Dotenv\Dotenv;
6
7
class CachePrefixIsSet implements Check
8
{
9
    /**
10
     * The name of the check.
11
     *
12
     * @param array $config
13
     * @return string
14
     */
15
    public function name(array $config): string
16
    {
17
        return trans('self-diagnosis::checks.cache_prefix_is_set.name');
18
    }
19
20
    /**
21
     * Perform the actual verification of this check.
22
     *
23
     * @param array $config
24
     * @return bool
25
     */
26 4
    public function check(array $config): bool
27
    {
28 4
        if (interface_exists(\Dotenv\Environment\FactoryInterface::class)) {
29 2
            $env = Dotenv::create(base_path(), '.env');
30
        } else {
31 2
            $env = new Dotenv(base_path(), '.env');
0 ignored issues
show
Documentation introduced by
base_path() is of type string, but the function expects a object<Dotenv\Loader>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
The call to Dotenv::__construct() has too many arguments starting with '.env'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
32
        }
33
34 4
        $env->safeLoad();
35
36 4
        return in_array('CACHE_PREFIX', $env->getEnvironmentVariableNames());
37
    }
38
39
    /**
40
     * The error message to display in case the check does not pass.
41
     *
42
     * @param array $config
43
     * @return string
44
     */
45 4
    public function message(array $config): string
46
    {
47 4
        return trans('self-diagnosis::checks.cache_prefix_is_set.message');
48
    }
49
}
50