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 (#1)
by Matthew
01:35
created

evaluate()   D

Complexity

Conditions 9
Paths 7

Size

Total Lines 39
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

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