Issues (98)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Schema/Lexer.php (8 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace HansOtt\GraphQL\Schema;
4
5
use HansOtt\GraphQL\Shared\ScannerGeneric;
6
use HansOtt\GraphQL\Shared\ScannerWithLocation;
7
use HansOtt\GraphQL\Shared\Lexer as LexerShared;
8
9
final class Lexer implements LexerShared
10
{
11
    /**
12
     * @var ScannerWithLocation
13
     */
14
    private $scanner;
15
    private $tokens;
16
17 15
    private function emit($type, $value, $location)
18
    {
19 15
        $this->tokens[] = new Token($type, $value, $location);
20 15
    }
21
22 15
    private function getLocation()
23
    {
24 15
        $line = $this->scanner->getLine();
25 15
        $column = $this->scanner->getColumn();
26
27 15
        return new Location($line, $column);
28
    }
29
30
    private function getError($message)
31
    {
32
        $line = $this->scanner->getLine();
33
        $column = $this->scanner->getColumn();
34
35
        return new SyntaxError($message . " (line {$line}, column {$column})");
36
    }
37
38 15
    private function name()
39
    {
40 15
        $name = $this->scanner->next();
41 15
        $location = $this->getLocation();
42
43 15
        if ($this->scanner->eof()) {
44 3
            $this->emit(Token::T_NAME, $name, $location);
45 3
            return;
46
        }
47
48 15
        $next = $this->scanner->peek();
49 15 View Code Duplication
        while ($next === '_' || ctype_alpha($next) || ctype_digit($next)) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50 15
            $name .= $this->scanner->next();
51 15
            if ($this->scanner->eof()) {
52
                break;
53
            }
54 15
            $next = $this->scanner->peek();
55 15
        }
56
57 15
        $type = Token::T_NAME;
58 15
        if ($name === 'true') {
59
            $type = Token::T_TRUE;
60 15
        } elseif ($name === 'false') {
61 3
            $type = Token::T_FALSE;
62 15
        } elseif ($name === 'null') {
63
            $type = Token::T_NULL;
64
        }
65
66 15
        $this->emit($type, $name, $location);
67 15
    }
68
69 View Code Duplication
    private function comment()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    {
71
        $this->scanner->next();
72
        $next = $this->scanner->peek();
73
        while ($this->scanner->eof() === false && $next !== "\n" && $next !== "\r") {
74
            $this->scanner->next();
75
            $next = $this->scanner->peek();
76
        }
77
    }
78
79 3 View Code Duplication
    private function str()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
    {
81 3
        $this->scanner->next();
82 3
        $location = $this->getLocation();
83 3
        $string = '';
84 3
        $previousChar = false;
85
86 3
        while (true) {
87 3
            if ($this->scanner->eof()) {
88
                throw $this->getError('Unclosed quote');
89
            }
90 3
            $next = $this->scanner->peek();
91 3
            if ($previousChar !== '\\' && $next === '"') {
92 3
                $this->scanner->next();
93 3
                break;
94
            }
95 3
            $previousChar = $this->scanner->next();
96 3
            $string .= $previousChar;
97 3
        }
98
99 3
        $string = json_decode('"' . $string . '"');
100 3
        $this->emit(Token::T_STRING, $string, $location);
101 3
    }
102
103 6 View Code Duplication
    private function integerPart()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
104
    {
105 6
        $number = $this->scanner->next();
106 6
        $location = $this->getLocation();
107 6
        if ($number === '-') {
108
            if ($this->scanner->eof()) {
109
                throw $this->getError('Expected a digit but instead reached end');
110
            }
111
            $next = $this->scanner->peek();
112
            if (ctype_digit($next) === false) {
113
                throw $this->getError("Expected a digit but instead found \"{$next}\"");
114
            }
115
        }
116
117 6
        $next = $this->scanner->peek();
118 6
        if ($next === '0') {
119
            $number .= $this->scanner->next();
120
            return array($number, $location);
121
        }
122
123 6
        $next = $this->scanner->peek();
124 6
        while ($this->scanner->eof() === false && ctype_digit($next)) {
125
            $number .= $this->scanner->next();
126
            $next = $this->scanner->peek();
127
        }
128
129 6
        return array($number, $location);
130
    }
131
132 3 View Code Duplication
    private function fractionalPart()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
133
    {
134 3
        $part = $this->scanner->next();
135
136 3
        if ($this->scanner->eof()) {
137
            throw $this->getError('Expected a digit but instead reached end');
138
        }
139
140 3
        $next = $this->scanner->peek();
141 3
        if (ctype_digit($next) === false) {
142
            throw $this->getError("Expected a digit but instead found \"{$next}\"");
143
        }
144
145 3
        $next = $this->scanner->peek();
146 3
        while ($this->scanner->eof() === false && ctype_digit($next)) {
147 3
            $part .= $this->scanner->next();
148 3
            $next = $this->scanner->peek();
149 3
        }
150
151 3
        return $part;
152
    }
153
154 View Code Duplication
    private function exponentPart()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
155
    {
156
        $part = $this->scanner->next();
157
158
        if ($this->scanner->eof()) {
159
            throw $this->getError('Expected a digit but instead reached end');
160
        }
161
162
        $next = $this->scanner->peek();
163
        if ($next === '+' || $next === '-') {
164
            $part .= $this->scanner->next();
165
        }
166
167
        $next = $this->scanner->peek();
168
        if (ctype_digit($next) === false) {
169
            throw $this->getError("Expected a digit but instead found \"{$next}\"");
170
        }
171
172
        $next = $this->scanner->peek();
173
        while ($this->scanner->eof() === false && ctype_digit($next)) {
174
            $part .= $this->scanner->next();
175
            $next = $this->scanner->peek();
176
        }
177
178
        return $part;
179
    }
180
181 6 View Code Duplication
    private function number()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
182
    {
183 6
        list ($integerPart, $location) = $this->integerPart();
184 6
        if ($this->scanner->eof()) {
185
            $this->emit(Token::T_INT, $integerPart, $location);
186
            return;
187
        }
188
189 6
        $next = $this->scanner->peek();
190 6
        if ($next !== '.' && $next !== 'e' && $next !== 'E') {
191 3
            $this->emit(Token::T_INT, $integerPart, $location);
192 3
            return;
193
        }
194
195 3
        $number = $integerPart;
196 3
        if ($next === '.') {
197 3
            $number .= $this->fractionalPart();
198 3
        }
199
200 3
        $next = $this->scanner->peek();
201 3
        if ($next === 'e' || $next === 'E') {
202
            $number .= $this->exponentPart();
203
        }
204
205 3
        $this->emit(Token::T_FLOAT, $number, $location);
206 3
    }
207
208
    /**
209
     * @param string $query
210
     *
211
     * @throws SyntaxError
212
     *
213
     * @return Token[]
214
     */
215 15
    public function lex($query)
216
    {
217 15
        $flags = PREG_SPLIT_NO_EMPTY;
218 15
        $chars = preg_split('//u', $query, -1, $flags);
219 15
        $scanner = new ScannerGeneric($chars);
220 15
        $this->scanner = new ScannerWithLocation($scanner);
221 15
        $this->tokens = array();
222
        $punctuators = array(
223 15
            '!' => Token::T_EXCLAMATION,
224 15
            '(' => Token::T_PAREN_LEFT,
225 15
            ')' => Token::T_PAREN_RIGHT,
226 15
            '{' => Token::T_BRACE_LEFT,
227 15
            '}' => Token::T_BRACE_RIGHT,
228 15
            ':' => Token::T_COLON,
229 15
            ',' => Token::T_COMMA,
230 15
            '[' => Token::T_BRACKET_LEFT,
231 15
            ']' => Token::T_BRACKET_RIGHT,
232 15
            '=' => Token::T_EQUAL,
233 15
            '|' => Token::T_PIPE,
234 15
        );
235
236 15 View Code Duplication
        while ($this->scanner->eof() === false) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
237 15
            $next = $this->scanner->peek();
238
239 15
            if (ctype_space($next)) {
240 15
                $this->scanner->next();
241 15
                continue;
242
            }
243
244 15
            if ($next === '#') {
245
                $this->comment();
246
                continue;
247
            }
248
249 15
            if ($next === '_' || ctype_alpha($next)) {
250 15
                $this->name();
251 15
                continue;
252
            }
253
254 15
            if ($next === '"') {
255 3
                $this->str();
256 3
                continue;
257
            }
258
259 15
            if ($next === '-' || ctype_digit($next)) {
260 6
                $this->number();
261 6
                continue;
262
            }
263
264 15
            if (isset($punctuators[$next])) {
265 15
                $this->emit($punctuators[$next], $this->scanner->next(), $this->getLocation());
266 15
                continue;
267
            }
268
269
            throw $this->getError("Unknown character: \"{$next}\"");
270
        }
271
272 15
        return $this->tokens;
273
    }
274
}
275