Passed
Push — master ( a58ba9...2e9b4a )
by Paweł
03:07
created

EnvAccess::get()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 3
rs 10
1
<?php
2
/**
3
 * Copyright (c) 2020.
4
 * @author Paweł Antosiak <[email protected]>
5
 */
6
7
declare(strict_types=1);
8
9
namespace Gorynych\Util;
10
11
use Gorynych\Exception\MissingEnvVariableException;
12
13
final class EnvAccess
14
{
15
    /**
16
     * Returns environmental variable by name
17
     *
18
     * @param string $name
19
     * @param mixed $default
20
     * @return mixed
21
     * @throws MissingEnvVariableException
22
     */
23 4
    public static function get(string $name, $default = null)
24
    {
25 4
        if (null === $default && false === array_key_exists($name, $_ENV)) {
26 1
            throw new MissingEnvVariableException($name);
27
        }
28
29 3
        return $_ENV[$name] ?? $default;
30
    }
31
}
32