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.
Completed
Push — master ( 5bd424...8b450b )
by Matthew
13s
created

Reader::read()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 7
rs 9.4285
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
12
    private $quotes;
13
14
    public function __construct($file)
15
    {
16
        if (!\is_resource($file) || get_resource_type($file) !== 'stream') {
17
            throw new \InvalidArgumentException('Must give me a file stream');
18
        }
19
20
        $this->quotes = [
21
            '\'' => Symbol::make('quote'),
22
            '``' => Symbol::make('quasiquote'),
23
            ',' => Symbol::make('unquote'),
24
            ',@' => Symbol::make('unquote-splicing'),
25
        ];
26
27
        $this->file = $file;
28
    }
29
30
    /**
31
     * @param $token
32
     * @return array|mixed
33
     * @throws \Exception
34
     */
35
    private function readAhead($token)
36
    {
37
        $this->guardAgainstUnexpectedEof($token);
38
        $this->guardAgainstInvalidExpression($token);
39
40
        if ($token === '(') {
41
            $l = [];
42
            while (true) {
43
                $token = $this->nextToken();
44
                if ($token === ')') {
45
                    return $l;
46
                }
47
48
                $l[] = $this->readAhead($token);
49
            }
50
        }
51
52
53
        if (isset($this->quotes[$token])) {
54
            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...
55
        }
56
57
        return atom($token);
58
    }
59
60
    public function read()
61
    {
62
        $first = $this->nextToken();
63
64
        return $first !== false
65
            ? $this->readAhead($first)
66
            : false;
67
    }
68
69
    /**
70
     * @return bool|string
71
     */
72
    public function nextToken()
73
    {
74
        while (true) {
75
            if ($this->line === '') {
76
                $this->line = fgets($this->file);
77
            }
78
79
            if ($this->line === false) {
80
                return $this->line;
81
            }
82
83
            preg_match($this->tokenizeRegexp, $this->line, $matches);
84
85
            [$_, $token, $this->line] = $matches;
86
87
            if ($token !== ';' || $token !== '') {
88
                return $token;
89
            }
90
        }
91
    }
92
93
    /**
94
     * @param $token
95
     * @throws \Exception
96
     */
97
    private function guardAgainstUnexpectedEof($token): void
98
    {
99
        if ($token === false) {
100
            throw new \Exception('unexpected eof!');
101
        }
102
    }
103
104
    /**
105
     * @param $token
106
     * @throws \Exception
107
     */
108
    private function guardAgainstInvalidExpression($token): void
109
    {
110
        if ($token === ')') {
111
            throw new \Exception('unexpected end of expression');
112
        }
113
    }
114
}