GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 749633...2fce5c )
by joseph
17:28 queued 14:47
created

SimpleEnv   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 90.48%

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 48
rs 10
c 0
b 0
f 0
ccs 19
cts 21
cp 0.9048
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setEnv() 0 11 4
A processLine() 0 32 4
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta;
4
5
use EdmondsCommerce\DoctrineStaticMeta\Exception\ConfigException;
6
7
/**
8
 * Class SimpleEnv
9
 *
10
 * A simplistic take on reading .env files
11
 *
12
 * We only require parsing very simple key=value pairs
13
 *
14
 * For a more fully featured library, see https://github.com/vlucas/phpdotenv
15
 *
16
 * @package EdmondsCommerce\DoctrineStaticMeta
17
 * @SuppressWarnings(PHPMD.Superglobals)
18
 */
19
class SimpleEnv
20
{
21 5
    public static function setEnv(string $filePath, array &$server = null): void
22
    {
23 5
        if (null === $server) {
24
            $server =& $_SERVER;
25
        }
26 5
        if (!file_exists($filePath)) {
27
            throw new ConfigException('Env file path ' . $filePath . ' does not exist');
28
        }
29 5
        $lines = file($filePath);
30 5
        foreach ($lines as $line) {
31 5
            self::processLine($line, $server);
0 ignored issues
show
Bug introduced by
It seems like $server can also be of type null; however, parameter $server of EdmondsCommerce\Doctrine...impleEnv::processLine() does only seem to accept array, 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

31
            self::processLine($line, /** @scrutinizer ignore-type */ $server);
Loading history...
32
        }
33 5
    }
34
35 5
    private static function processLine(string $line, array &$server): void
36
    {
37
        #skip comments
38 5
        if (preg_match('%^\s*#%', $line)) {
39 1
            return;
40
        }
41 5
        preg_match(
42
            #strip leading spaces
43
            '%^[[:space:]]*'
44
            #strip leading `export`
45
            . '(?:export[[:space:]]+|)'
46
            #parse out the key and assign to named match
47
            . '(?<key>[^=]+?)'
48
            #strip out `=`, possibly with space around it
49
            . '[[:space:]]*=[[:space:]]*'
50
            #strip out possible quotes
51
            . "(?:\"|'|)"
52
            #parse out the value and assign to named match
53
            . "(?<value>[^\"']+?)"
54
            #strip out possible quotes
55
            . "(?:\"|'|)"
56
            #string out trailing space to end of line
57 5
            . '[[:space:]]*$%',
58 5
            $line,
59 5
            $matches
60
        );
61 5
        if (5 !== count($matches)) {
62 1
            return;
63
        }
64 5
        list(, $key, $value) = $matches;
65 5
        if (!isset($server[$key])) {
66 5
            $server[$key] = $value;
67
        }
68 5
    }
69
}
70