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.
Passed
Push — master ( 9b41ee...0d3ad3 )
by Enjoys
03:58
created

ValuesHandler::handleVariables()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 3
dl 0
loc 12
ccs 8
cts 8
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
6
namespace Enjoys\Dotenv;
7
8
9
use Webmozart\Assert\Assert;
10
11
final class ValuesHandler
12
{
13 13
    public static  function quotes(string $value): string
14
    {
15 13
        return preg_replace('/^\"(.+)\"$/', '\\1', $value);
16
    }
17
18
    /**
19
     * @param string $value
20
     * @return bool|float|int|string|null
21
     */
22 13
    public static function cast(string $value)
23
    {
24 13
        preg_match('/^\*(\w+)[\s+]?(.+)?/', $value, $match);
25
26 13
        $v = $match[2] ?? '';
27
28 13
        switch ($match[1] ?? '') {
29 13
            case 'true':
30 1
                return true;
31 13
            case 'false':
32 1
                return false;
33 13
            case 'null':
34 1
                return null;
35 13
            case 'int':
36 2
                Assert::notEmpty($v, 'Invalid parameter for *int type, the value must not be empty');
37 1
                return (int)$v;
38 12
            case 'int8':
39 2
                Assert::notEmpty($v, 'Invalid parameter for *int type, the value must not be empty');
40 1
                return octdec($v);
41 11
            case 'int16':
42 2
                Assert::notEmpty($v, 'Invalid parameter for *int type, the value must not be empty');
43 1
                return hexdec($v);
44 10
            case 'float':
45 2
                Assert::notEmpty($v, 'Invalid parameter for *float type, the value must not be empty');
46 1
                return (float)str_replace(',', '.', $v);
47 9
            case 'string':
48 2
                Assert::notEmpty($v, 'Invalid parameter for *string type, the value must not be empty');
49 1
                return $v;
50
            default:
51 8
                return $value;
52
        }
53
    }
54
55 13
    public static function handleVariables(string $key, string $value, Dotenv $dotenv): string
56
    {
57 13
        $result =  preg_replace_callback(
58 13
            '/(\${(.+?)})/',
59 13
            function (array $matches) use ($dotenv){
60
                /** @var string[] $matches */
61 2
                return $dotenv->getEnvArray()[$matches[2]] ?? '';
62 13
            },
63
            $value
64
        );
65 13
        $dotenv->setEnvArrayOne($key, $result);
66 13
        return $result;
67
    }
68
}