@@ -11,15 +11,13 @@ discard block |
||
11 | 11 | |
12 | 12 | namespace Seld\PharUtils; |
13 | 13 | |
14 | -class Linter |
|
15 | -{ |
|
14 | +class Linter { |
|
16 | 15 | /** |
17 | 16 | * Lints all php files inside a given phar with the current PHP version |
18 | 17 | * |
19 | 18 | * @param string $path Phar file path |
20 | 19 | */ |
21 | - public static function lint($path) |
|
22 | - { |
|
20 | + public static function lint($path) { |
|
23 | 21 | $php = defined('PHP_BINARY') ? PHP_BINARY : 'php'; |
24 | 22 | |
25 | 23 | if ($isWindows = defined('PHP_WINDOWS_VERSION_BUILD')) { |
@@ -98,8 +96,7 @@ discard block |
||
98 | 96 | * @param string $path |
99 | 97 | * @return string The escaped path |
100 | 98 | */ |
101 | - private static function escapeWindowsPath($path) |
|
102 | - { |
|
99 | + private static function escapeWindowsPath($path) { |
|
103 | 100 | // Quote if path contains spaces or brackets |
104 | 101 | if (strpbrk($path, " ()") !== false) { |
105 | 102 | $path = '"'.$path.'"'; |
@@ -25,8 +25,7 @@ discard block |
||
25 | 25 | * |
26 | 26 | * Ported from https://github.com/zaach/jsonlint |
27 | 27 | */ |
28 | -class JsonParser |
|
29 | -{ |
|
28 | +class JsonParser { |
|
30 | 29 | const DETECT_KEY_CONFLICTS = 1; |
31 | 30 | const ALLOW_DUPLICATE_KEYS = 2; |
32 | 31 | const PARSE_TO_ASSOC = 4; |
@@ -126,8 +125,7 @@ discard block |
||
126 | 125 | * @param int $flags Bitmask of parse/lint options (see constants of this class) |
127 | 126 | * @return null|ParsingException null if no error is found, a ParsingException containing all details otherwise |
128 | 127 | */ |
129 | - public function lint($input, $flags = 0) |
|
130 | - { |
|
128 | + public function lint($input, $flags = 0) { |
|
131 | 129 | try { |
132 | 130 | $this->parse($input, $flags); |
133 | 131 | } catch (ParsingException $e) { |
@@ -142,8 +140,7 @@ discard block |
||
142 | 140 | * @return mixed |
143 | 141 | * @throws ParsingException |
144 | 142 | */ |
145 | - public function parse($input, $flags = 0) |
|
146 | - { |
|
143 | + public function parse($input, $flags = 0) { |
|
147 | 144 | $this->failOnBOM($input); |
148 | 145 | |
149 | 146 | $this->flags = $flags; |
@@ -284,7 +281,8 @@ discard block |
||
284 | 281 | $this->lstack[] = $this->lexer->yylloc; |
285 | 282 | $this->stack[] = $action[1]; // push state |
286 | 283 | $symbol = null; |
287 | - if (!$preErrorSymbol) { // normal execution/no error |
|
284 | + if (!$preErrorSymbol) { |
|
285 | +// normal execution/no error |
|
288 | 286 | $yyleng = $this->lexer->yyleng; |
289 | 287 | $yytext = $this->lexer->yytext; |
290 | 288 | $yylineno = $this->lexer->yylineno; |
@@ -292,7 +290,8 @@ discard block |
||
292 | 290 | if ($recovering > 0) { |
293 | 291 | $recovering--; |
294 | 292 | } |
295 | - } else { // error just occurred, resume old lookahead f/ before error |
|
293 | + } else { |
|
294 | +// error just occurred, resume old lookahead f/ before error |
|
296 | 295 | $symbol = $preErrorSymbol; |
297 | 296 | $preErrorSymbol = null; |
298 | 297 | } |
@@ -334,16 +333,14 @@ discard block |
||
334 | 333 | } |
335 | 334 | } |
336 | 335 | |
337 | - protected function parseError($str, $hash) |
|
338 | - { |
|
336 | + protected function parseError($str, $hash) { |
|
339 | 337 | throw new ParsingException($str, $hash); |
340 | 338 | } |
341 | 339 | |
342 | 340 | // $$ = $tokens // needs to be passed by ref? |
343 | 341 | // $ = $token |
344 | 342 | // _$ removed, useless? |
345 | - private function performAction(stdClass $yyval, $yytext, $yyleng, $yylineno, $yystate, &$tokens) |
|
346 | - { |
|
343 | + private function performAction(stdClass $yyval, $yytext, $yyleng, $yylineno, $yystate, &$tokens) { |
|
347 | 344 | // $0 = $len |
348 | 345 | $len = \count($tokens) - 1; |
349 | 346 | switch ($yystate) { |
@@ -453,8 +450,7 @@ discard block |
||
453 | 450 | return new Undefined(); |
454 | 451 | } |
455 | 452 | |
456 | - private function stringInterpolation($match) |
|
457 | - { |
|
453 | + private function stringInterpolation($match) { |
|
458 | 454 | switch ($match[0]) { |
459 | 455 | case '\\\\': |
460 | 456 | return '\\'; |
@@ -477,15 +473,13 @@ discard block |
||
477 | 473 | } |
478 | 474 | } |
479 | 475 | |
480 | - private function popStack($n) |
|
481 | - { |
|
476 | + private function popStack($n) { |
|
482 | 477 | $this->stack = \array_slice($this->stack, 0, - (2 * $n)); |
483 | 478 | $this->vstack = \array_slice($this->vstack, 0, - $n); |
484 | 479 | $this->lstack = \array_slice($this->lstack, 0, - $n); |
485 | 480 | } |
486 | 481 | |
487 | - private function lex() |
|
488 | - { |
|
482 | + private function lex() { |
|
489 | 483 | $token = $this->lexer->lex() ?: 1; // $end = 1 |
490 | 484 | // if token isn't its numeric value, convert |
491 | 485 | if (!is_numeric($token)) { |
@@ -495,8 +489,7 @@ discard block |
||
495 | 489 | return $token; |
496 | 490 | } |
497 | 491 | |
498 | - private function failOnBOM($input) |
|
499 | - { |
|
492 | + private function failOnBOM($input) { |
|
500 | 493 | // UTF-8 ByteOrderMark sequence |
501 | 494 | $bom = "\xEF\xBB\xBF"; |
502 | 495 |
@@ -11,29 +11,25 @@ |
||
11 | 11 | |
12 | 12 | namespace Seld\JsonLint; |
13 | 13 | |
14 | -class DuplicateKeyException extends ParsingException |
|
15 | -{ |
|
14 | +class DuplicateKeyException extends ParsingException { |
|
16 | 15 | /** |
17 | 16 | * @param string $message |
18 | 17 | * @param string $key |
19 | 18 | * @phpstan-param array{text?: string, token?: string, line?: int, loc?: array{first_line: int, first_column: int, last_line: int, last_column: int}, expected?: string[]} $details |
20 | 19 | */ |
21 | - public function __construct($message, $key, array $details = array()) |
|
22 | - { |
|
20 | + public function __construct($message, $key, array $details = array()) { |
|
23 | 21 | $details['key'] = $key; |
24 | 22 | parent::__construct($message, $details); |
25 | 23 | } |
26 | 24 | |
27 | - public function getKey() |
|
28 | - { |
|
25 | + public function getKey() { |
|
29 | 26 | return $this->details['key']; |
30 | 27 | } |
31 | 28 | |
32 | 29 | /** |
33 | 30 | * @phpstan-return array{text?: string, token?: string, line?: int, loc?: array{first_line: int, first_column: int, last_line: int, last_column: int}, expected?: string[], key: string} |
34 | 31 | */ |
35 | - public function getDetails() |
|
36 | - { |
|
32 | + public function getDetails() { |
|
37 | 33 | return $this->details; |
38 | 34 | } |
39 | 35 | } |
@@ -16,8 +16,7 @@ discard block |
||
16 | 16 | * |
17 | 17 | * Ported from https://github.com/zaach/jsonlint |
18 | 18 | */ |
19 | -class Lexer |
|
20 | -{ |
|
19 | +class Lexer { |
|
21 | 20 | private $EOF = 1; |
22 | 21 | /** |
23 | 22 | * @phpstan-var array<int, string> |
@@ -58,8 +57,7 @@ discard block |
||
58 | 57 | public $yytext; |
59 | 58 | public $yylloc; |
60 | 59 | |
61 | - public function lex() |
|
62 | - { |
|
60 | + public function lex() { |
|
63 | 61 | $r = $this->next(); |
64 | 62 | if (!$r instanceof Undefined) { |
65 | 63 | return $r; |
@@ -68,8 +66,7 @@ discard block |
||
68 | 66 | return $this->lex(); |
69 | 67 | } |
70 | 68 | |
71 | - public function setInput($input) |
|
72 | - { |
|
69 | + public function setInput($input) { |
|
73 | 70 | $this->input = $input; |
74 | 71 | $this->more = false; |
75 | 72 | $this->done = false; |
@@ -82,23 +79,20 @@ discard block |
||
82 | 79 | return $this; |
83 | 80 | } |
84 | 81 | |
85 | - public function showPosition() |
|
86 | - { |
|
82 | + public function showPosition() { |
|
87 | 83 | $pre = str_replace("\n", '', $this->getPastInput()); |
88 | 84 | $c = str_repeat('-', max(0, \strlen($pre) - 1)); // new Array(pre.length + 1).join("-"); |
89 | 85 | |
90 | 86 | return $pre . str_replace("\n", '', $this->getUpcomingInput()) . "\n" . $c . "^"; |
91 | 87 | } |
92 | 88 | |
93 | - public function getPastInput() |
|
94 | - { |
|
89 | + public function getPastInput() { |
|
95 | 90 | $pastLength = $this->offset - \strlen($this->match); |
96 | 91 | |
97 | 92 | return ($pastLength > 20 ? '...' : '') . substr($this->input, max(0, $pastLength - 20), min(20, $pastLength)); |
98 | 93 | } |
99 | 94 | |
100 | - public function getUpcomingInput() |
|
101 | - { |
|
95 | + public function getUpcomingInput() { |
|
102 | 96 | $next = $this->match; |
103 | 97 | if (\strlen($next) < 20) { |
104 | 98 | $next .= substr($this->input, $this->offset, 20 - \strlen($next)); |
@@ -107,8 +101,7 @@ discard block |
||
107 | 101 | return substr($next, 0, 20) . (\strlen($next) > 20 ? '...' : ''); |
108 | 102 | } |
109 | 103 | |
110 | - public function getFullUpcomingInput() |
|
111 | - { |
|
104 | + public function getFullUpcomingInput() { |
|
112 | 105 | $next = $this->match; |
113 | 106 | if (substr($next, 0, 1) === '"' && substr_count($next, '"') === 1) { |
114 | 107 | $len = \strlen($this->input); |
@@ -121,13 +114,11 @@ discard block |
||
121 | 114 | return $next; |
122 | 115 | } |
123 | 116 | |
124 | - protected function parseError($str, $hash) |
|
125 | - { |
|
117 | + protected function parseError($str, $hash) { |
|
126 | 118 | throw new \Exception($str); |
127 | 119 | } |
128 | 120 | |
129 | - private function next() |
|
130 | - { |
|
121 | + private function next() { |
|
131 | 122 | if ($this->done) { |
132 | 123 | return $this->EOF; |
133 | 124 | } |
@@ -190,13 +181,11 @@ discard block |
||
190 | 181 | ); |
191 | 182 | } |
192 | 183 | |
193 | - private function getCurrentRules() |
|
194 | - { |
|
184 | + private function getCurrentRules() { |
|
195 | 185 | return $this->conditions[$this->conditionStack[\count($this->conditionStack)-1]]['rules']; |
196 | 186 | } |
197 | 187 | |
198 | - private function performAction($avoiding_name_collisions, $YY_START) |
|
199 | - { |
|
188 | + private function performAction($avoiding_name_collisions, $YY_START) { |
|
200 | 189 | switch ($avoiding_name_collisions) { |
201 | 190 | case 0:/* skip whitespace */ |
202 | 191 | break; |
@@ -11,6 +11,5 @@ |
||
11 | 11 | |
12 | 12 | namespace Seld\JsonLint; |
13 | 13 | |
14 | -class Undefined |
|
15 | -{ |
|
14 | +class Undefined { |
|
16 | 15 | } |
@@ -11,16 +11,14 @@ discard block |
||
11 | 11 | |
12 | 12 | namespace Seld\JsonLint; |
13 | 13 | |
14 | -class ParsingException extends \Exception |
|
15 | -{ |
|
14 | +class ParsingException extends \Exception { |
|
16 | 15 | protected $details; |
17 | 16 | |
18 | 17 | /** |
19 | 18 | * @param string $message |
20 | 19 | * @phpstan-param array{text?: string, token?: string, line?: int, loc?: array{first_line: int, first_column: int, last_line: int, last_column: int}, expected?: string[]} $details |
21 | 20 | */ |
22 | - public function __construct($message, $details = array()) |
|
23 | - { |
|
21 | + public function __construct($message, $details = array()) { |
|
24 | 22 | $this->details = $details; |
25 | 23 | parent::__construct($message); |
26 | 24 | } |
@@ -28,8 +26,7 @@ discard block |
||
28 | 26 | /** |
29 | 27 | * @phpstan-return array{text?: string, token?: string, line?: int, loc?: array{first_line: int, first_column: int, last_line: int, last_column: int}, expected?: string[]} |
30 | 28 | */ |
31 | - public function getDetails() |
|
32 | - { |
|
29 | + public function getDetails() { |
|
33 | 30 | return $this->details; |
34 | 31 | } |
35 | 32 | } |
@@ -5,6 +5,5 @@ |
||
5 | 5 | /** |
6 | 6 | * No entry was found in the container. |
7 | 7 | */ |
8 | -interface NotFoundExceptionInterface extends ContainerExceptionInterface |
|
9 | -{ |
|
8 | +interface NotFoundExceptionInterface extends ContainerExceptionInterface { |
|
10 | 9 | } |
@@ -7,8 +7,7 @@ |
||
7 | 7 | /** |
8 | 8 | * Describes the interface of a container that exposes methods to read its entries. |
9 | 9 | */ |
10 | -interface ContainerInterface |
|
11 | -{ |
|
10 | +interface ContainerInterface { |
|
12 | 11 | /** |
13 | 12 | * Finds an entry of the container by its identifier and returns it. |
14 | 13 | * |
@@ -5,6 +5,5 @@ |
||
5 | 5 | /** |
6 | 6 | * Base interface representing a generic exception in a container. |
7 | 7 | */ |
8 | -interface ContainerExceptionInterface |
|
9 | -{ |
|
8 | +interface ContainerExceptionInterface { |
|
10 | 9 | } |