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

EnvAccess   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 17
ccs 4
cts 4
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 7 3
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