Env   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 14

1 Method

Rating   Name   Duplication   Size   Complexity  
C __invoke() 0 34 14
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: afshin
5
 * Date: 11/11/17
6
 * Time: 2:57 PM
7
 */
8
9
namespace Core\Helpers;
10
use Dotenv\Dotenv;
11
12
class Env
13
{
14
    public function __invoke($filePath ,$key, $default = null)
15
    {
16
        if (file_exists($filePath . '.env')) {
17
            $_dotenv = new Dotenv($filePath );
18
            $_dotenv->load();
19
            unset($_dotenv);
20
        }else {
21
            return '';
22
        }
23
        $value = getenv($key);
24
25
        if ($value === false) {
26
            return $default;
27
        }
28
        switch (strtolower($value)) {
0 ignored issues
show
Bug introduced by
It seems like $value can also be of type array; however, parameter $str of strtolower() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
        switch (strtolower(/** @scrutinizer ignore-type */ $value)) {
Loading history...
29
            case 'true':
30
            case '(true)':
31
                return true;
32
            case 'false':
33
            case '(false)':
34
                return false;
35
            case 'empty':
36
            case '(empty)':
37
                return '';
38
            case 'null':
39
            case '(null)':
40
                return null;
41
        }
42
        $strLen = strlen($value);
0 ignored issues
show
Bug introduced by
It seems like $value can also be of type array; however, parameter $string of strlen() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

42
        $strLen = strlen(/** @scrutinizer ignore-type */ $value);
Loading history...
43
44
        if ($strLen > 1 && $value[0] === '"' && $value[$strLen - 1] === '"') {
45
            return substr($value, 1, -1);
0 ignored issues
show
Bug introduced by
It seems like $value can also be of type array; however, parameter $string of substr() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
            return substr(/** @scrutinizer ignore-type */ $value, 1, -1);
Loading history...
46
        }
47
        return $value;
48
    }
49
}