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 ( b6b4f0...d9bb99 )
by Matthew
01:38
created

Reader::guardAgainstInvalidExpression()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sphpeme;
4
5
class Reader
6
{
7
    private $tokenizeRegexp = '/\s*(,@|[(\'`,)]|"(?:[\\].|[^\\"])*"|;.*|[^\s(\'"`,;)]*)(.*)/';
8
    private $file;
9
    private $line = '';
10
11
    private $quotes;
12
13
    public static function fromStream($stream)
14
    {
15
        if (!\is_resource($stream) || get_resource_type($stream) !== 'stream') {
16
            throw new \InvalidArgumentException('Must give me a file stream');
17
        }
18
19
        return new static($stream);
20
    }
21
22
    public static function fromFilepath($filepath)
23
    {
24
        if (!file_exists($filepath)) {
25
            throw new \InvalidArgumentException("{$filepath} does not exist or is not readable.");
26
        }
27
28
        return new static(fopen($filepath, 'r+b'));
29
    }
30
31
    private function __construct($file)
32
    {
33
        $this->quotes = [
34
            '\'' => Symbol::make('quote'),
35
            '``' => Symbol::make('quasiquote'),
36
            ',' => Symbol::make('unquote'),
37
            ',@' => Symbol::make('unquote-splicing'),
38
        ];
39
40
        $this->file = $file;
41
    }
42
43
    /**
44
     * @param $token
45
     * @return array|mixed
46
     * @throws \Exception
47
     */
48
    private function readAhead($token)
49
    {
50
        $this->guardAgainstUnexpectedEof($token);
51
        $this->guardAgainstInvalidExpression($token);
52
53
        if ($token === '(') {
54
            $l = [];
55
            while (true) {
56
                $token = $this->nextToken();
57
                if ($token === ')') {
58
                    return $l;
59
                }
60
61
                $l[] = $this->readAhead($token);
62
            }
63
        }
64
65
66
        if (isset($this->quotes[$token])) {
67
            return [$this->quotes[$token], $this->read()];
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->read() targeting Sphpeme\Reader::read() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
68
        }
69
70
        return atom($token);
71
    }
72
73
    public function read()
74
    {
75
        $first = $this->nextToken();
76
77
        return $first !== false
78
            ? $this->readAhead($first)
79
            : false;
80
    }
81
82
    /**
83
     * @return bool|string
84
     */
85
    public function nextToken()
86
    {
87
        while (true) {
88
            if ($this->line === '') {
89
                $this->line = fgets($this->file);
90
            }
91
92
            if ($this->line === false) {
93
                return $this->line;
94
            }
95
96
            preg_match($this->tokenizeRegexp, $this->line, $matches);
97
98
            [$_, $token, $this->line] = $matches;
99
100
            if ($token !== ';' || $token !== '') {
101
                return $token;
102
            }
103
        }
104
    }
105
106
    /**
107
     * @param $token
108
     * @throws \Exception
109
     */
110
    private function guardAgainstUnexpectedEof($token): void
111
    {
112
        if ($token === false) {
113
            throw new \Exception('unexpected eof!');
114
        }
115
    }
116
117
    /**
118
     * @param $token
119
     * @throws \Exception
120
     */
121
    private function guardAgainstInvalidExpression($token): void
122
    {
123
        if ($token === ')') {
124
            throw new \Exception('unexpected end of expression');
125
        }
126
    }
127
}