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
Pull Request — master (#2)
by Matthew
01:37
created

atom()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 4
nop 1
dl 0
loc 17
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace Sphpeme;
4
5
/**
6
 * Parse the given value as its scalar type
7
 *
8
 * @param $val
9
 * @return mixed
10
 */
11
function atom($val)
12
{
13
    if (is_numeric($val)) {
14
        return new Scalar(strpos($val, '.')
15
            ? (float)$val
16
            : (int)$val);
17
    }
18
19
    if (strpos($val, '"') === 0) {
20
        return new Scalar(str_replace('"', '', $val));
21
    }
22
23
    if (\is_bool($val)) {
24
        return new Scalar($val);
25
    }
26
27
    return new Symbol($val);
28
}
29
30
/**
31
 * Tokenize the program string for parsing
32
 *
33
 * @param $programStr
34
 * @return array tokenized program
35
 */
36
function tokenize($programStr): array
37
{
38
    return array_map('trim',
39
        explode(' ', str_replace(['(', ')'], ['( ', ' )'], $programStr)));
40
}
41
42
/**
43
 * Generate an AST given an array of tokens
44
 *
45
 * @param array $tokens
46
 * @return array AST
47
 */
48
function parse(array $tokens): array
49
{
50
    $stack = [];
51
    foreach ($tokens as $token) {
52
        switch ($token) {
53
            case '(':
54
                $stack = [[], $stack];
55
                break;
56
            case ')':
57
                [$exp, $stack] = $stack;
58
                $stack[0][] = $exp;
59
                break;
60
            case strpos($token, ';;') !== 0:
61
                $stack[0][] = atom($token);
62
                break;
63
            default:
64
                break;
65
        }
66
    }
67
68
    return $stack[0][0] ?? [];
69
}
70
71
/**
72
 * Extend the given env with the extension values
73
 *
74
 * @param Env $env
75
 * @param array $extends
76
 * @return Env
77
 */
78
function env_extend(Env $env, array $extends)
79
{
80
    $myenv = clone $env;
81
    foreach ($extends as $key => $value) {
82
        $myenv->$key = $value;
83
    }
84
85
    return $myenv;
86
}
87
88
89
/**
90
 * Provides access to Sphpeme's std env
91
 *
92
 * @return Env
93
 */
94
function get_std_env(): Env
95
{
96
    return require __DIR__ . '/stdenv.php';
97
}
98