@@ -13,180 +13,180 @@ |
||
13 | 13 | |
14 | 14 | class Timestamps |
15 | 15 | { |
16 | - private $contents; |
|
17 | - |
|
18 | - /** |
|
19 | - * @param string $file path to the phar file to use |
|
20 | - */ |
|
21 | - public function __construct($file) |
|
22 | - { |
|
23 | - $this->contents = file_get_contents($file); |
|
24 | - } |
|
25 | - |
|
26 | - /** |
|
27 | - * Updates each file's unix timestamps in the PHAR |
|
28 | - * |
|
29 | - * The PHAR signature can then be produced in a reproducible manner. |
|
30 | - * |
|
31 | - * @param int|\DateTimeInterface|string $timestamp Date string or DateTime or unix timestamp to use |
|
32 | - */ |
|
33 | - public function updateTimestamps($timestamp = null) |
|
34 | - { |
|
35 | - if ($timestamp instanceof \DateTime || $timestamp instanceof \DateTimeInterface) { |
|
36 | - $timestamp = $timestamp->getTimestamp(); |
|
37 | - } elseif (is_string($timestamp)) { |
|
38 | - $timestamp = strtotime($timestamp); |
|
39 | - } elseif (!is_int($timestamp)) { |
|
40 | - $timestamp = strtotime('1984-12-24T00:00:00Z'); |
|
41 | - } |
|
42 | - |
|
43 | - // detect manifest offset / end of stub |
|
44 | - if (!preg_match('{__HALT_COMPILER\(\);(?: +\?>)?\r?\n}', $this->contents, $match, PREG_OFFSET_CAPTURE)) { |
|
45 | - throw new \RuntimeException('Could not detect the stub\'s end in the phar'); |
|
46 | - } |
|
47 | - |
|
48 | - // set starting position and skip past manifest length |
|
49 | - $pos = $match[0][1] + strlen($match[0][0]); |
|
50 | - $stubEnd = $pos + $this->readUint($pos, 4); |
|
51 | - $pos += 4; |
|
52 | - |
|
53 | - $numFiles = $this->readUint($pos, 4); |
|
54 | - $pos += 4; |
|
55 | - |
|
56 | - // skip API version (YOLO) |
|
57 | - $pos += 2; |
|
58 | - |
|
59 | - // skip PHAR flags |
|
60 | - $pos += 4; |
|
61 | - |
|
62 | - $aliasLength = $this->readUint($pos, 4); |
|
63 | - $pos += 4 + $aliasLength; |
|
64 | - |
|
65 | - $metadataLength = $this->readUint($pos, 4); |
|
66 | - $pos += 4 + $metadataLength; |
|
67 | - |
|
68 | - while ($pos < $stubEnd) { |
|
69 | - $filenameLength = $this->readUint($pos, 4); |
|
70 | - $pos += 4 + $filenameLength; |
|
71 | - |
|
72 | - // skip filesize |
|
73 | - $pos += 4; |
|
74 | - |
|
75 | - // update timestamp to a fixed value |
|
76 | - $this->contents = substr_replace($this->contents, pack('L', $timestamp), $pos, 4); |
|
77 | - |
|
78 | - // skip timestamp, compressed file size, crc32 checksum and file flags |
|
79 | - $pos += 4*4; |
|
80 | - |
|
81 | - $metadataLength = $this->readUint($pos, 4); |
|
82 | - $pos += 4 + $metadataLength; |
|
83 | - |
|
84 | - $numFiles--; |
|
85 | - } |
|
86 | - |
|
87 | - if ($numFiles !== 0) { |
|
88 | - throw new \LogicException('All files were not processed, something must have gone wrong'); |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Saves the updated phar file, optionally with an updated signature. |
|
94 | - * |
|
95 | - * @param string $path |
|
96 | - * @param int $signatureAlgo One of Phar::MD5, Phar::SHA1, Phar::SHA256 or Phar::SHA512 |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - public function save($path, $signatureAlgo) |
|
100 | - { |
|
101 | - $pos = $this->determineSignatureBegin(); |
|
102 | - |
|
103 | - $algos = array( |
|
104 | - \Phar::MD5 => 'md5', |
|
105 | - \Phar::SHA1 => 'sha1', |
|
106 | - \Phar::SHA256 => 'sha256', |
|
107 | - \Phar::SHA512 => 'sha512', |
|
108 | - ); |
|
109 | - |
|
110 | - if (!isset($algos[$signatureAlgo])) { |
|
111 | - throw new \UnexpectedValueException('Invalid hash algorithm given: '.$signatureAlgo.' expected one of Phar::MD5, Phar::SHA1, Phar::SHA256 or Phar::SHA512'); |
|
112 | - } |
|
113 | - $algo = $algos[$signatureAlgo]; |
|
114 | - |
|
115 | - // re-sign phar |
|
116 | - // signature |
|
117 | - $signature = hash($algo, substr($this->contents, 0, $pos), true) |
|
118 | - // sig type |
|
119 | - . pack('L', $signatureAlgo) |
|
120 | - // ohai Greg & Marcus |
|
121 | - . 'GBMB'; |
|
122 | - |
|
123 | - $this->contents = substr($this->contents, 0, $pos) . $signature; |
|
124 | - |
|
125 | - return file_put_contents($path, $this->contents); |
|
126 | - } |
|
127 | - |
|
128 | - private function readUint($pos, $bytes) |
|
129 | - { |
|
130 | - $res = unpack('V', substr($this->contents, $pos, $bytes)); |
|
131 | - |
|
132 | - return $res[1]; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Determine the beginning of the signature. |
|
137 | - * |
|
138 | - * @return int |
|
139 | - */ |
|
140 | - private function determineSignatureBegin() |
|
141 | - { |
|
142 | - // detect signature position |
|
143 | - if (!preg_match('{__HALT_COMPILER\(\);(?: +\?>)?\r?\n}', $this->contents, $match, PREG_OFFSET_CAPTURE)) { |
|
144 | - throw new \RuntimeException('Could not detect the stub\'s end in the phar'); |
|
145 | - } |
|
16 | + private $contents; |
|
17 | + |
|
18 | + /** |
|
19 | + * @param string $file path to the phar file to use |
|
20 | + */ |
|
21 | + public function __construct($file) |
|
22 | + { |
|
23 | + $this->contents = file_get_contents($file); |
|
24 | + } |
|
25 | + |
|
26 | + /** |
|
27 | + * Updates each file's unix timestamps in the PHAR |
|
28 | + * |
|
29 | + * The PHAR signature can then be produced in a reproducible manner. |
|
30 | + * |
|
31 | + * @param int|\DateTimeInterface|string $timestamp Date string or DateTime or unix timestamp to use |
|
32 | + */ |
|
33 | + public function updateTimestamps($timestamp = null) |
|
34 | + { |
|
35 | + if ($timestamp instanceof \DateTime || $timestamp instanceof \DateTimeInterface) { |
|
36 | + $timestamp = $timestamp->getTimestamp(); |
|
37 | + } elseif (is_string($timestamp)) { |
|
38 | + $timestamp = strtotime($timestamp); |
|
39 | + } elseif (!is_int($timestamp)) { |
|
40 | + $timestamp = strtotime('1984-12-24T00:00:00Z'); |
|
41 | + } |
|
42 | + |
|
43 | + // detect manifest offset / end of stub |
|
44 | + if (!preg_match('{__HALT_COMPILER\(\);(?: +\?>)?\r?\n}', $this->contents, $match, PREG_OFFSET_CAPTURE)) { |
|
45 | + throw new \RuntimeException('Could not detect the stub\'s end in the phar'); |
|
46 | + } |
|
47 | + |
|
48 | + // set starting position and skip past manifest length |
|
49 | + $pos = $match[0][1] + strlen($match[0][0]); |
|
50 | + $stubEnd = $pos + $this->readUint($pos, 4); |
|
51 | + $pos += 4; |
|
52 | + |
|
53 | + $numFiles = $this->readUint($pos, 4); |
|
54 | + $pos += 4; |
|
55 | + |
|
56 | + // skip API version (YOLO) |
|
57 | + $pos += 2; |
|
58 | + |
|
59 | + // skip PHAR flags |
|
60 | + $pos += 4; |
|
61 | + |
|
62 | + $aliasLength = $this->readUint($pos, 4); |
|
63 | + $pos += 4 + $aliasLength; |
|
64 | + |
|
65 | + $metadataLength = $this->readUint($pos, 4); |
|
66 | + $pos += 4 + $metadataLength; |
|
67 | + |
|
68 | + while ($pos < $stubEnd) { |
|
69 | + $filenameLength = $this->readUint($pos, 4); |
|
70 | + $pos += 4 + $filenameLength; |
|
71 | + |
|
72 | + // skip filesize |
|
73 | + $pos += 4; |
|
74 | + |
|
75 | + // update timestamp to a fixed value |
|
76 | + $this->contents = substr_replace($this->contents, pack('L', $timestamp), $pos, 4); |
|
77 | + |
|
78 | + // skip timestamp, compressed file size, crc32 checksum and file flags |
|
79 | + $pos += 4*4; |
|
80 | + |
|
81 | + $metadataLength = $this->readUint($pos, 4); |
|
82 | + $pos += 4 + $metadataLength; |
|
83 | + |
|
84 | + $numFiles--; |
|
85 | + } |
|
86 | + |
|
87 | + if ($numFiles !== 0) { |
|
88 | + throw new \LogicException('All files were not processed, something must have gone wrong'); |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Saves the updated phar file, optionally with an updated signature. |
|
94 | + * |
|
95 | + * @param string $path |
|
96 | + * @param int $signatureAlgo One of Phar::MD5, Phar::SHA1, Phar::SHA256 or Phar::SHA512 |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + public function save($path, $signatureAlgo) |
|
100 | + { |
|
101 | + $pos = $this->determineSignatureBegin(); |
|
102 | + |
|
103 | + $algos = array( |
|
104 | + \Phar::MD5 => 'md5', |
|
105 | + \Phar::SHA1 => 'sha1', |
|
106 | + \Phar::SHA256 => 'sha256', |
|
107 | + \Phar::SHA512 => 'sha512', |
|
108 | + ); |
|
109 | + |
|
110 | + if (!isset($algos[$signatureAlgo])) { |
|
111 | + throw new \UnexpectedValueException('Invalid hash algorithm given: '.$signatureAlgo.' expected one of Phar::MD5, Phar::SHA1, Phar::SHA256 or Phar::SHA512'); |
|
112 | + } |
|
113 | + $algo = $algos[$signatureAlgo]; |
|
114 | + |
|
115 | + // re-sign phar |
|
116 | + // signature |
|
117 | + $signature = hash($algo, substr($this->contents, 0, $pos), true) |
|
118 | + // sig type |
|
119 | + . pack('L', $signatureAlgo) |
|
120 | + // ohai Greg & Marcus |
|
121 | + . 'GBMB'; |
|
122 | + |
|
123 | + $this->contents = substr($this->contents, 0, $pos) . $signature; |
|
124 | + |
|
125 | + return file_put_contents($path, $this->contents); |
|
126 | + } |
|
127 | + |
|
128 | + private function readUint($pos, $bytes) |
|
129 | + { |
|
130 | + $res = unpack('V', substr($this->contents, $pos, $bytes)); |
|
131 | + |
|
132 | + return $res[1]; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Determine the beginning of the signature. |
|
137 | + * |
|
138 | + * @return int |
|
139 | + */ |
|
140 | + private function determineSignatureBegin() |
|
141 | + { |
|
142 | + // detect signature position |
|
143 | + if (!preg_match('{__HALT_COMPILER\(\);(?: +\?>)?\r?\n}', $this->contents, $match, PREG_OFFSET_CAPTURE)) { |
|
144 | + throw new \RuntimeException('Could not detect the stub\'s end in the phar'); |
|
145 | + } |
|
146 | 146 | |
147 | - // set starting position and skip past manifest length |
|
148 | - $pos = $match[0][1] + strlen($match[0][0]); |
|
149 | - $manifestEnd = $pos + 4 + $this->readUint($pos, 4); |
|
147 | + // set starting position and skip past manifest length |
|
148 | + $pos = $match[0][1] + strlen($match[0][0]); |
|
149 | + $manifestEnd = $pos + 4 + $this->readUint($pos, 4); |
|
150 | 150 | |
151 | - $pos += 4; |
|
152 | - $numFiles = $this->readUint($pos, 4); |
|
151 | + $pos += 4; |
|
152 | + $numFiles = $this->readUint($pos, 4); |
|
153 | 153 | |
154 | - $pos += 4; |
|
154 | + $pos += 4; |
|
155 | 155 | |
156 | - // skip API version (YOLO) |
|
157 | - $pos += 2; |
|
156 | + // skip API version (YOLO) |
|
157 | + $pos += 2; |
|
158 | 158 | |
159 | - // skip PHAR flags |
|
160 | - $pos += 4; |
|
159 | + // skip PHAR flags |
|
160 | + $pos += 4; |
|
161 | 161 | |
162 | - $aliasLength = $this->readUint($pos, 4); |
|
163 | - $pos += 4 + $aliasLength; |
|
164 | - |
|
165 | - $metadataLength = $this->readUint($pos, 4); |
|
166 | - $pos += 4 + $metadataLength; |
|
167 | - |
|
168 | - $compressedSizes = 0; |
|
169 | - while (($numFiles > 0) && ($pos < $manifestEnd - 24)) { |
|
170 | - $filenameLength = $this->readUint($pos, 4); |
|
171 | - $pos += 4 + $filenameLength; |
|
172 | - |
|
173 | - // skip filesize and timestamp |
|
174 | - $pos += 2*4; |
|
175 | - |
|
176 | - $compressedSizes += $this->readUint($pos, 4); |
|
177 | - // skip compressed file size, crc32 checksum and file flags |
|
178 | - $pos += 3*4; |
|
179 | - |
|
180 | - $metadataLength = $this->readUint($pos, 4); |
|
181 | - $pos += 4 + $metadataLength; |
|
182 | - |
|
183 | - $numFiles--; |
|
184 | - } |
|
185 | - |
|
186 | - if ($numFiles !== 0) { |
|
187 | - throw new \LogicException('All files were not processed, something must have gone wrong'); |
|
188 | - } |
|
189 | - |
|
190 | - return $manifestEnd + $compressedSizes; |
|
191 | - } |
|
162 | + $aliasLength = $this->readUint($pos, 4); |
|
163 | + $pos += 4 + $aliasLength; |
|
164 | + |
|
165 | + $metadataLength = $this->readUint($pos, 4); |
|
166 | + $pos += 4 + $metadataLength; |
|
167 | + |
|
168 | + $compressedSizes = 0; |
|
169 | + while (($numFiles > 0) && ($pos < $manifestEnd - 24)) { |
|
170 | + $filenameLength = $this->readUint($pos, 4); |
|
171 | + $pos += 4 + $filenameLength; |
|
172 | + |
|
173 | + // skip filesize and timestamp |
|
174 | + $pos += 2*4; |
|
175 | + |
|
176 | + $compressedSizes += $this->readUint($pos, 4); |
|
177 | + // skip compressed file size, crc32 checksum and file flags |
|
178 | + $pos += 3*4; |
|
179 | + |
|
180 | + $metadataLength = $this->readUint($pos, 4); |
|
181 | + $pos += 4 + $metadataLength; |
|
182 | + |
|
183 | + $numFiles--; |
|
184 | + } |
|
185 | + |
|
186 | + if ($numFiles !== 0) { |
|
187 | + throw new \LogicException('All files were not processed, something must have gone wrong'); |
|
188 | + } |
|
189 | + |
|
190 | + return $manifestEnd + $compressedSizes; |
|
191 | + } |
|
192 | 192 | } |
@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @param string $file path to the phar file to use |
20 | 20 | */ |
21 | - public function __construct($file) |
|
21 | + public function __construct( $file ) |
|
22 | 22 | { |
23 | - $this->contents = file_get_contents($file); |
|
23 | + $this->contents = file_get_contents( $file ); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -30,27 +30,27 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @param int|\DateTimeInterface|string $timestamp Date string or DateTime or unix timestamp to use |
32 | 32 | */ |
33 | - public function updateTimestamps($timestamp = null) |
|
33 | + public function updateTimestamps( $timestamp = null ) |
|
34 | 34 | { |
35 | - if ($timestamp instanceof \DateTime || $timestamp instanceof \DateTimeInterface) { |
|
35 | + if ( $timestamp instanceof \DateTime || $timestamp instanceof \DateTimeInterface ) { |
|
36 | 36 | $timestamp = $timestamp->getTimestamp(); |
37 | - } elseif (is_string($timestamp)) { |
|
38 | - $timestamp = strtotime($timestamp); |
|
39 | - } elseif (!is_int($timestamp)) { |
|
40 | - $timestamp = strtotime('1984-12-24T00:00:00Z'); |
|
37 | + } elseif ( is_string( $timestamp ) ) { |
|
38 | + $timestamp = strtotime( $timestamp ); |
|
39 | + } elseif ( ! is_int( $timestamp ) ) { |
|
40 | + $timestamp = strtotime( '1984-12-24T00:00:00Z' ); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | // detect manifest offset / end of stub |
44 | - if (!preg_match('{__HALT_COMPILER\(\);(?: +\?>)?\r?\n}', $this->contents, $match, PREG_OFFSET_CAPTURE)) { |
|
45 | - throw new \RuntimeException('Could not detect the stub\'s end in the phar'); |
|
44 | + if ( ! preg_match( '{__HALT_COMPILER\(\);(?: +\?>)?\r?\n}', $this->contents, $match, PREG_OFFSET_CAPTURE ) ) { |
|
45 | + throw new \RuntimeException( 'Could not detect the stub\'s end in the phar' ); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | // set starting position and skip past manifest length |
49 | - $pos = $match[0][1] + strlen($match[0][0]); |
|
50 | - $stubEnd = $pos + $this->readUint($pos, 4); |
|
49 | + $pos = $match[ 0 ][ 1 ] + strlen( $match[ 0 ][ 0 ] ); |
|
50 | + $stubEnd = $pos + $this->readUint( $pos, 4 ); |
|
51 | 51 | $pos += 4; |
52 | 52 | |
53 | - $numFiles = $this->readUint($pos, 4); |
|
53 | + $numFiles = $this->readUint( $pos, 4 ); |
|
54 | 54 | $pos += 4; |
55 | 55 | |
56 | 56 | // skip API version (YOLO) |
@@ -59,33 +59,33 @@ discard block |
||
59 | 59 | // skip PHAR flags |
60 | 60 | $pos += 4; |
61 | 61 | |
62 | - $aliasLength = $this->readUint($pos, 4); |
|
62 | + $aliasLength = $this->readUint( $pos, 4 ); |
|
63 | 63 | $pos += 4 + $aliasLength; |
64 | 64 | |
65 | - $metadataLength = $this->readUint($pos, 4); |
|
65 | + $metadataLength = $this->readUint( $pos, 4 ); |
|
66 | 66 | $pos += 4 + $metadataLength; |
67 | 67 | |
68 | - while ($pos < $stubEnd) { |
|
69 | - $filenameLength = $this->readUint($pos, 4); |
|
68 | + while ( $pos < $stubEnd ) { |
|
69 | + $filenameLength = $this->readUint( $pos, 4 ); |
|
70 | 70 | $pos += 4 + $filenameLength; |
71 | 71 | |
72 | 72 | // skip filesize |
73 | 73 | $pos += 4; |
74 | 74 | |
75 | 75 | // update timestamp to a fixed value |
76 | - $this->contents = substr_replace($this->contents, pack('L', $timestamp), $pos, 4); |
|
76 | + $this->contents = substr_replace( $this->contents, pack( 'L', $timestamp ), $pos, 4 ); |
|
77 | 77 | |
78 | 78 | // skip timestamp, compressed file size, crc32 checksum and file flags |
79 | - $pos += 4*4; |
|
79 | + $pos += 4 * 4; |
|
80 | 80 | |
81 | - $metadataLength = $this->readUint($pos, 4); |
|
81 | + $metadataLength = $this->readUint( $pos, 4 ); |
|
82 | 82 | $pos += 4 + $metadataLength; |
83 | 83 | |
84 | 84 | $numFiles--; |
85 | 85 | } |
86 | 86 | |
87 | - if ($numFiles !== 0) { |
|
88 | - throw new \LogicException('All files were not processed, something must have gone wrong'); |
|
87 | + if ( $numFiles !== 0 ) { |
|
88 | + throw new \LogicException( 'All files were not processed, something must have gone wrong' ); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @param int $signatureAlgo One of Phar::MD5, Phar::SHA1, Phar::SHA256 or Phar::SHA512 |
97 | 97 | * @return bool |
98 | 98 | */ |
99 | - public function save($path, $signatureAlgo) |
|
99 | + public function save( $path, $signatureAlgo ) |
|
100 | 100 | { |
101 | 101 | $pos = $this->determineSignatureBegin(); |
102 | 102 | |
@@ -107,29 +107,29 @@ discard block |
||
107 | 107 | \Phar::SHA512 => 'sha512', |
108 | 108 | ); |
109 | 109 | |
110 | - if (!isset($algos[$signatureAlgo])) { |
|
111 | - throw new \UnexpectedValueException('Invalid hash algorithm given: '.$signatureAlgo.' expected one of Phar::MD5, Phar::SHA1, Phar::SHA256 or Phar::SHA512'); |
|
110 | + if ( ! isset( $algos[ $signatureAlgo ] ) ) { |
|
111 | + throw new \UnexpectedValueException( 'Invalid hash algorithm given: ' . $signatureAlgo . ' expected one of Phar::MD5, Phar::SHA1, Phar::SHA256 or Phar::SHA512' ); |
|
112 | 112 | } |
113 | - $algo = $algos[$signatureAlgo]; |
|
113 | + $algo = $algos[ $signatureAlgo ]; |
|
114 | 114 | |
115 | 115 | // re-sign phar |
116 | 116 | // signature |
117 | - $signature = hash($algo, substr($this->contents, 0, $pos), true) |
|
117 | + $signature = hash( $algo, substr( $this->contents, 0, $pos ), true ) |
|
118 | 118 | // sig type |
119 | - . pack('L', $signatureAlgo) |
|
119 | + . pack( 'L', $signatureAlgo ) |
|
120 | 120 | // ohai Greg & Marcus |
121 | 121 | . 'GBMB'; |
122 | 122 | |
123 | - $this->contents = substr($this->contents, 0, $pos) . $signature; |
|
123 | + $this->contents = substr( $this->contents, 0, $pos ) . $signature; |
|
124 | 124 | |
125 | - return file_put_contents($path, $this->contents); |
|
125 | + return file_put_contents( $path, $this->contents ); |
|
126 | 126 | } |
127 | 127 | |
128 | - private function readUint($pos, $bytes) |
|
128 | + private function readUint( $pos, $bytes ) |
|
129 | 129 | { |
130 | - $res = unpack('V', substr($this->contents, $pos, $bytes)); |
|
130 | + $res = unpack( 'V', substr( $this->contents, $pos, $bytes ) ); |
|
131 | 131 | |
132 | - return $res[1]; |
|
132 | + return $res[ 1 ]; |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -140,16 +140,16 @@ discard block |
||
140 | 140 | private function determineSignatureBegin() |
141 | 141 | { |
142 | 142 | // detect signature position |
143 | - if (!preg_match('{__HALT_COMPILER\(\);(?: +\?>)?\r?\n}', $this->contents, $match, PREG_OFFSET_CAPTURE)) { |
|
144 | - throw new \RuntimeException('Could not detect the stub\'s end in the phar'); |
|
143 | + if ( ! preg_match( '{__HALT_COMPILER\(\);(?: +\?>)?\r?\n}', $this->contents, $match, PREG_OFFSET_CAPTURE ) ) { |
|
144 | + throw new \RuntimeException( 'Could not detect the stub\'s end in the phar' ); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | // set starting position and skip past manifest length |
148 | - $pos = $match[0][1] + strlen($match[0][0]); |
|
149 | - $manifestEnd = $pos + 4 + $this->readUint($pos, 4); |
|
148 | + $pos = $match[ 0 ][ 1 ] + strlen( $match[ 0 ][ 0 ] ); |
|
149 | + $manifestEnd = $pos + 4 + $this->readUint( $pos, 4 ); |
|
150 | 150 | |
151 | 151 | $pos += 4; |
152 | - $numFiles = $this->readUint($pos, 4); |
|
152 | + $numFiles = $this->readUint( $pos, 4 ); |
|
153 | 153 | |
154 | 154 | $pos += 4; |
155 | 155 | |
@@ -159,32 +159,32 @@ discard block |
||
159 | 159 | // skip PHAR flags |
160 | 160 | $pos += 4; |
161 | 161 | |
162 | - $aliasLength = $this->readUint($pos, 4); |
|
162 | + $aliasLength = $this->readUint( $pos, 4 ); |
|
163 | 163 | $pos += 4 + $aliasLength; |
164 | 164 | |
165 | - $metadataLength = $this->readUint($pos, 4); |
|
165 | + $metadataLength = $this->readUint( $pos, 4 ); |
|
166 | 166 | $pos += 4 + $metadataLength; |
167 | 167 | |
168 | 168 | $compressedSizes = 0; |
169 | - while (($numFiles > 0) && ($pos < $manifestEnd - 24)) { |
|
170 | - $filenameLength = $this->readUint($pos, 4); |
|
169 | + while ( ( $numFiles > 0 ) && ( $pos < $manifestEnd - 24 ) ) { |
|
170 | + $filenameLength = $this->readUint( $pos, 4 ); |
|
171 | 171 | $pos += 4 + $filenameLength; |
172 | 172 | |
173 | 173 | // skip filesize and timestamp |
174 | - $pos += 2*4; |
|
174 | + $pos += 2 * 4; |
|
175 | 175 | |
176 | - $compressedSizes += $this->readUint($pos, 4); |
|
176 | + $compressedSizes += $this->readUint( $pos, 4 ); |
|
177 | 177 | // skip compressed file size, crc32 checksum and file flags |
178 | - $pos += 3*4; |
|
178 | + $pos += 3 * 4; |
|
179 | 179 | |
180 | - $metadataLength = $this->readUint($pos, 4); |
|
180 | + $metadataLength = $this->readUint( $pos, 4 ); |
|
181 | 181 | $pos += 4 + $metadataLength; |
182 | 182 | |
183 | 183 | $numFiles--; |
184 | 184 | } |
185 | 185 | |
186 | - if ($numFiles !== 0) { |
|
187 | - throw new \LogicException('All files were not processed, something must have gone wrong'); |
|
186 | + if ( $numFiles !== 0 ) { |
|
187 | + throw new \LogicException( 'All files were not processed, something must have gone wrong' ); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | return $manifestEnd + $compressedSizes; |
@@ -11,15 +11,13 @@ discard block |
||
11 | 11 | |
12 | 12 | namespace Seld\PharUtils; |
13 | 13 | |
14 | -class Timestamps |
|
15 | -{ |
|
14 | +class Timestamps { |
|
16 | 15 | private $contents; |
17 | 16 | |
18 | 17 | /** |
19 | 18 | * @param string $file path to the phar file to use |
20 | 19 | */ |
21 | - public function __construct($file) |
|
22 | - { |
|
20 | + public function __construct($file) { |
|
23 | 21 | $this->contents = file_get_contents($file); |
24 | 22 | } |
25 | 23 | |
@@ -30,8 +28,7 @@ discard block |
||
30 | 28 | * |
31 | 29 | * @param int|\DateTimeInterface|string $timestamp Date string or DateTime or unix timestamp to use |
32 | 30 | */ |
33 | - public function updateTimestamps($timestamp = null) |
|
34 | - { |
|
31 | + public function updateTimestamps($timestamp = null) { |
|
35 | 32 | if ($timestamp instanceof \DateTime || $timestamp instanceof \DateTimeInterface) { |
36 | 33 | $timestamp = $timestamp->getTimestamp(); |
37 | 34 | } elseif (is_string($timestamp)) { |
@@ -96,8 +93,7 @@ discard block |
||
96 | 93 | * @param int $signatureAlgo One of Phar::MD5, Phar::SHA1, Phar::SHA256 or Phar::SHA512 |
97 | 94 | * @return bool |
98 | 95 | */ |
99 | - public function save($path, $signatureAlgo) |
|
100 | - { |
|
96 | + public function save($path, $signatureAlgo) { |
|
101 | 97 | $pos = $this->determineSignatureBegin(); |
102 | 98 | |
103 | 99 | $algos = array( |
@@ -125,8 +121,7 @@ discard block |
||
125 | 121 | return file_put_contents($path, $this->contents); |
126 | 122 | } |
127 | 123 | |
128 | - private function readUint($pos, $bytes) |
|
129 | - { |
|
124 | + private function readUint($pos, $bytes) { |
|
130 | 125 | $res = unpack('V', substr($this->contents, $pos, $bytes)); |
131 | 126 | |
132 | 127 | return $res[1]; |
@@ -137,8 +132,7 @@ discard block |
||
137 | 132 | * |
138 | 133 | * @return int |
139 | 134 | */ |
140 | - private function determineSignatureBegin() |
|
141 | - { |
|
135 | + private function determineSignatureBegin() { |
|
142 | 136 | // detect signature position |
143 | 137 | if (!preg_match('{__HALT_COMPILER\(\);(?: +\?>)?\r?\n}', $this->contents, $match, PREG_OFFSET_CAPTURE)) { |
144 | 138 | throw new \RuntimeException('Could not detect the stub\'s end in the phar'); |
@@ -13,98 +13,98 @@ |
||
13 | 13 | |
14 | 14 | class Linter |
15 | 15 | { |
16 | - /** |
|
17 | - * Lints all php files inside a given phar with the current PHP version |
|
18 | - * |
|
19 | - * @param string $path Phar file path |
|
20 | - */ |
|
21 | - public static function lint($path) |
|
22 | - { |
|
23 | - $php = defined('PHP_BINARY') ? PHP_BINARY : 'php'; |
|
24 | - |
|
25 | - if ($isWindows = defined('PHP_WINDOWS_VERSION_BUILD')) { |
|
26 | - $tmpFile = @tempnam(sys_get_temp_dir(), ''); |
|
27 | - |
|
28 | - if (!$tmpFile || !is_writable($tmpFile)) { |
|
29 | - throw new \RuntimeException('Unable to create temp file'); |
|
30 | - } |
|
31 | - |
|
32 | - $php = self::escapeWindowsPath($php); |
|
33 | - $tmpFile = self::escapeWindowsPath($tmpFile); |
|
34 | - |
|
35 | - // PHP 8 encloses the command in double-quotes |
|
36 | - if (PHP_VERSION_ID >= 80000) { |
|
37 | - $format = '%s -l %s'; |
|
38 | - } else { |
|
39 | - $format = '"%s -l %s"'; |
|
40 | - } |
|
41 | - |
|
42 | - $command = sprintf($format, $php, $tmpFile); |
|
43 | - } else { |
|
44 | - $command = "'".$php."' -l"; |
|
45 | - } |
|
46 | - |
|
47 | - $descriptorspec = array( |
|
48 | - 0 => array('pipe', 'r'), |
|
49 | - 1 => array('pipe', 'w'), |
|
50 | - 2 => array('pipe', 'w') |
|
51 | - ); |
|
52 | - |
|
53 | - foreach (new \RecursiveIteratorIterator(new \Phar($path)) as $file) { |
|
54 | - if ($file->isDir()) { |
|
55 | - continue; |
|
56 | - } |
|
57 | - if (substr($file, -4) === '.php') { |
|
58 | - $filename = (string) $file; |
|
59 | - |
|
60 | - if ($isWindows) { |
|
61 | - file_put_contents($tmpFile, file_get_contents($filename)); |
|
62 | - } |
|
63 | - |
|
64 | - $process = proc_open($command, $descriptorspec, $pipes); |
|
65 | - if (is_resource($process)) { |
|
66 | - if (!$isWindows) { |
|
67 | - fwrite($pipes[0], file_get_contents($filename)); |
|
68 | - } |
|
69 | - fclose($pipes[0]); |
|
70 | - |
|
71 | - $stdout = stream_get_contents($pipes[1]); |
|
72 | - fclose($pipes[1]); |
|
73 | - $stderr = stream_get_contents($pipes[2]); |
|
74 | - fclose($pipes[2]); |
|
75 | - |
|
76 | - $exitCode = proc_close($process); |
|
77 | - |
|
78 | - if ($exitCode !== 0) { |
|
79 | - if ($isWindows) { |
|
80 | - $stderr = str_replace($tmpFile, $filename, $stderr); |
|
81 | - } |
|
82 | - throw new \UnexpectedValueException('Failed linting '.$file.': '.$stderr); |
|
83 | - } |
|
84 | - } else { |
|
85 | - throw new \RuntimeException('Could not start linter process'); |
|
86 | - } |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - if ($isWindows) { |
|
91 | - @unlink($tmpFile); |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Escapes a Windows file path |
|
97 | - * |
|
98 | - * @param string $path |
|
99 | - * @return string The escaped path |
|
100 | - */ |
|
101 | - private static function escapeWindowsPath($path) |
|
102 | - { |
|
103 | - // Quote if path contains spaces or brackets |
|
104 | - if (strpbrk($path, " ()") !== false) { |
|
105 | - $path = '"'.$path.'"'; |
|
106 | - } |
|
107 | - |
|
108 | - return $path; |
|
109 | - } |
|
16 | + /** |
|
17 | + * Lints all php files inside a given phar with the current PHP version |
|
18 | + * |
|
19 | + * @param string $path Phar file path |
|
20 | + */ |
|
21 | + public static function lint($path) |
|
22 | + { |
|
23 | + $php = defined('PHP_BINARY') ? PHP_BINARY : 'php'; |
|
24 | + |
|
25 | + if ($isWindows = defined('PHP_WINDOWS_VERSION_BUILD')) { |
|
26 | + $tmpFile = @tempnam(sys_get_temp_dir(), ''); |
|
27 | + |
|
28 | + if (!$tmpFile || !is_writable($tmpFile)) { |
|
29 | + throw new \RuntimeException('Unable to create temp file'); |
|
30 | + } |
|
31 | + |
|
32 | + $php = self::escapeWindowsPath($php); |
|
33 | + $tmpFile = self::escapeWindowsPath($tmpFile); |
|
34 | + |
|
35 | + // PHP 8 encloses the command in double-quotes |
|
36 | + if (PHP_VERSION_ID >= 80000) { |
|
37 | + $format = '%s -l %s'; |
|
38 | + } else { |
|
39 | + $format = '"%s -l %s"'; |
|
40 | + } |
|
41 | + |
|
42 | + $command = sprintf($format, $php, $tmpFile); |
|
43 | + } else { |
|
44 | + $command = "'".$php."' -l"; |
|
45 | + } |
|
46 | + |
|
47 | + $descriptorspec = array( |
|
48 | + 0 => array('pipe', 'r'), |
|
49 | + 1 => array('pipe', 'w'), |
|
50 | + 2 => array('pipe', 'w') |
|
51 | + ); |
|
52 | + |
|
53 | + foreach (new \RecursiveIteratorIterator(new \Phar($path)) as $file) { |
|
54 | + if ($file->isDir()) { |
|
55 | + continue; |
|
56 | + } |
|
57 | + if (substr($file, -4) === '.php') { |
|
58 | + $filename = (string) $file; |
|
59 | + |
|
60 | + if ($isWindows) { |
|
61 | + file_put_contents($tmpFile, file_get_contents($filename)); |
|
62 | + } |
|
63 | + |
|
64 | + $process = proc_open($command, $descriptorspec, $pipes); |
|
65 | + if (is_resource($process)) { |
|
66 | + if (!$isWindows) { |
|
67 | + fwrite($pipes[0], file_get_contents($filename)); |
|
68 | + } |
|
69 | + fclose($pipes[0]); |
|
70 | + |
|
71 | + $stdout = stream_get_contents($pipes[1]); |
|
72 | + fclose($pipes[1]); |
|
73 | + $stderr = stream_get_contents($pipes[2]); |
|
74 | + fclose($pipes[2]); |
|
75 | + |
|
76 | + $exitCode = proc_close($process); |
|
77 | + |
|
78 | + if ($exitCode !== 0) { |
|
79 | + if ($isWindows) { |
|
80 | + $stderr = str_replace($tmpFile, $filename, $stderr); |
|
81 | + } |
|
82 | + throw new \UnexpectedValueException('Failed linting '.$file.': '.$stderr); |
|
83 | + } |
|
84 | + } else { |
|
85 | + throw new \RuntimeException('Could not start linter process'); |
|
86 | + } |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + if ($isWindows) { |
|
91 | + @unlink($tmpFile); |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Escapes a Windows file path |
|
97 | + * |
|
98 | + * @param string $path |
|
99 | + * @return string The escaped path |
|
100 | + */ |
|
101 | + private static function escapeWindowsPath($path) |
|
102 | + { |
|
103 | + // Quote if path contains spaces or brackets |
|
104 | + if (strpbrk($path, " ()") !== false) { |
|
105 | + $path = '"'.$path.'"'; |
|
106 | + } |
|
107 | + |
|
108 | + return $path; |
|
109 | + } |
|
110 | 110 | } |
@@ -18,77 +18,77 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @param string $path Phar file path |
20 | 20 | */ |
21 | - public static function lint($path) |
|
21 | + public static function lint( $path ) |
|
22 | 22 | { |
23 | - $php = defined('PHP_BINARY') ? PHP_BINARY : 'php'; |
|
23 | + $php = defined( 'PHP_BINARY' ) ? PHP_BINARY : 'php'; |
|
24 | 24 | |
25 | - if ($isWindows = defined('PHP_WINDOWS_VERSION_BUILD')) { |
|
26 | - $tmpFile = @tempnam(sys_get_temp_dir(), ''); |
|
25 | + if ( $isWindows = defined( 'PHP_WINDOWS_VERSION_BUILD' ) ) { |
|
26 | + $tmpFile = @tempnam( sys_get_temp_dir(), '' ); |
|
27 | 27 | |
28 | - if (!$tmpFile || !is_writable($tmpFile)) { |
|
29 | - throw new \RuntimeException('Unable to create temp file'); |
|
28 | + if ( ! $tmpFile || ! is_writable( $tmpFile ) ) { |
|
29 | + throw new \RuntimeException( 'Unable to create temp file' ); |
|
30 | 30 | } |
31 | 31 | |
32 | - $php = self::escapeWindowsPath($php); |
|
33 | - $tmpFile = self::escapeWindowsPath($tmpFile); |
|
32 | + $php = self::escapeWindowsPath( $php ); |
|
33 | + $tmpFile = self::escapeWindowsPath( $tmpFile ); |
|
34 | 34 | |
35 | 35 | // PHP 8 encloses the command in double-quotes |
36 | - if (PHP_VERSION_ID >= 80000) { |
|
36 | + if ( PHP_VERSION_ID >= 80000 ) { |
|
37 | 37 | $format = '%s -l %s'; |
38 | 38 | } else { |
39 | 39 | $format = '"%s -l %s"'; |
40 | 40 | } |
41 | 41 | |
42 | - $command = sprintf($format, $php, $tmpFile); |
|
42 | + $command = sprintf( $format, $php, $tmpFile ); |
|
43 | 43 | } else { |
44 | - $command = "'".$php."' -l"; |
|
44 | + $command = "'" . $php . "' -l"; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | $descriptorspec = array( |
48 | - 0 => array('pipe', 'r'), |
|
49 | - 1 => array('pipe', 'w'), |
|
50 | - 2 => array('pipe', 'w') |
|
48 | + 0 => array( 'pipe', 'r' ), |
|
49 | + 1 => array( 'pipe', 'w' ), |
|
50 | + 2 => array( 'pipe', 'w' ) |
|
51 | 51 | ); |
52 | 52 | |
53 | - foreach (new \RecursiveIteratorIterator(new \Phar($path)) as $file) { |
|
54 | - if ($file->isDir()) { |
|
53 | + foreach ( new \RecursiveIteratorIterator( new \Phar( $path ) ) as $file ) { |
|
54 | + if ( $file->isDir() ) { |
|
55 | 55 | continue; |
56 | 56 | } |
57 | - if (substr($file, -4) === '.php') { |
|
58 | - $filename = (string) $file; |
|
57 | + if ( substr( $file, -4 ) === '.php' ) { |
|
58 | + $filename = (string)$file; |
|
59 | 59 | |
60 | - if ($isWindows) { |
|
61 | - file_put_contents($tmpFile, file_get_contents($filename)); |
|
60 | + if ( $isWindows ) { |
|
61 | + file_put_contents( $tmpFile, file_get_contents( $filename ) ); |
|
62 | 62 | } |
63 | 63 | |
64 | - $process = proc_open($command, $descriptorspec, $pipes); |
|
65 | - if (is_resource($process)) { |
|
66 | - if (!$isWindows) { |
|
67 | - fwrite($pipes[0], file_get_contents($filename)); |
|
64 | + $process = proc_open( $command, $descriptorspec, $pipes ); |
|
65 | + if ( is_resource( $process ) ) { |
|
66 | + if ( ! $isWindows ) { |
|
67 | + fwrite( $pipes[ 0 ], file_get_contents( $filename ) ); |
|
68 | 68 | } |
69 | - fclose($pipes[0]); |
|
69 | + fclose( $pipes[ 0 ] ); |
|
70 | 70 | |
71 | - $stdout = stream_get_contents($pipes[1]); |
|
72 | - fclose($pipes[1]); |
|
73 | - $stderr = stream_get_contents($pipes[2]); |
|
74 | - fclose($pipes[2]); |
|
71 | + $stdout = stream_get_contents( $pipes[ 1 ] ); |
|
72 | + fclose( $pipes[ 1 ] ); |
|
73 | + $stderr = stream_get_contents( $pipes[ 2 ] ); |
|
74 | + fclose( $pipes[ 2 ] ); |
|
75 | 75 | |
76 | - $exitCode = proc_close($process); |
|
76 | + $exitCode = proc_close( $process ); |
|
77 | 77 | |
78 | - if ($exitCode !== 0) { |
|
79 | - if ($isWindows) { |
|
80 | - $stderr = str_replace($tmpFile, $filename, $stderr); |
|
78 | + if ( $exitCode !== 0 ) { |
|
79 | + if ( $isWindows ) { |
|
80 | + $stderr = str_replace( $tmpFile, $filename, $stderr ); |
|
81 | 81 | } |
82 | - throw new \UnexpectedValueException('Failed linting '.$file.': '.$stderr); |
|
82 | + throw new \UnexpectedValueException( 'Failed linting ' . $file . ': ' . $stderr ); |
|
83 | 83 | } |
84 | 84 | } else { |
85 | - throw new \RuntimeException('Could not start linter process'); |
|
85 | + throw new \RuntimeException( 'Could not start linter process' ); |
|
86 | 86 | } |
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
90 | - if ($isWindows) { |
|
91 | - @unlink($tmpFile); |
|
90 | + if ( $isWindows ) { |
|
91 | + @unlink( $tmpFile ); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | * @param string $path |
99 | 99 | * @return string The escaped path |
100 | 100 | */ |
101 | - private static function escapeWindowsPath($path) |
|
101 | + private static function escapeWindowsPath( $path ) |
|
102 | 102 | { |
103 | 103 | // Quote if path contains spaces or brackets |
104 | - if (strpbrk($path, " ()") !== false) { |
|
105 | - $path = '"'.$path.'"'; |
|
104 | + if ( strpbrk( $path, " ()" ) !== false ) { |
|
105 | + $path = '"' . $path . '"'; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | return $path; |
@@ -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.'"'; |
@@ -27,481 +27,481 @@ |
||
27 | 27 | */ |
28 | 28 | class JsonParser |
29 | 29 | { |
30 | - const DETECT_KEY_CONFLICTS = 1; |
|
31 | - const ALLOW_DUPLICATE_KEYS = 2; |
|
32 | - const PARSE_TO_ASSOC = 4; |
|
33 | - |
|
34 | - private $lexer; |
|
35 | - |
|
36 | - private $flags; |
|
37 | - private $stack; |
|
38 | - private $vstack; // semantic value stack |
|
39 | - private $lstack; // location stack |
|
40 | - |
|
41 | - /** |
|
42 | - * @phpstan-var array<string, int> |
|
43 | - */ |
|
44 | - private $symbols = array( |
|
45 | - 'error' => 2, |
|
46 | - 'JSONString' => 3, |
|
47 | - 'STRING' => 4, |
|
48 | - 'JSONNumber' => 5, |
|
49 | - 'NUMBER' => 6, |
|
50 | - 'JSONNullLiteral' => 7, |
|
51 | - 'NULL' => 8, |
|
52 | - 'JSONBooleanLiteral' => 9, |
|
53 | - 'TRUE' => 10, |
|
54 | - 'FALSE' => 11, |
|
55 | - 'JSONText' => 12, |
|
56 | - 'JSONValue' => 13, |
|
57 | - 'EOF' => 14, |
|
58 | - 'JSONObject' => 15, |
|
59 | - 'JSONArray' => 16, |
|
60 | - '{' => 17, |
|
61 | - '}' => 18, |
|
62 | - 'JSONMemberList' => 19, |
|
63 | - 'JSONMember' => 20, |
|
64 | - ':' => 21, |
|
65 | - ',' => 22, |
|
66 | - '[' => 23, |
|
67 | - ']' => 24, |
|
68 | - 'JSONElementList' => 25, |
|
69 | - '$accept' => 0, |
|
70 | - '$end' => 1, |
|
71 | - ); |
|
72 | - |
|
73 | - /** |
|
74 | - * @phpstan-var array<int, string> |
|
75 | - */ |
|
76 | - private $terminals_ = array( |
|
77 | - 2 => "error", |
|
78 | - 4 => "STRING", |
|
79 | - 6 => "NUMBER", |
|
80 | - 8 => "NULL", |
|
81 | - 10 => "TRUE", |
|
82 | - 11 => "FALSE", |
|
83 | - 14 => "EOF", |
|
84 | - 17 => "{", |
|
85 | - 18 => "}", |
|
86 | - 21 => ":", |
|
87 | - 22 => ",", |
|
88 | - 23 => "[", |
|
89 | - 24 => "]", |
|
90 | - ); |
|
91 | - |
|
92 | - private $productions_ = array( |
|
93 | - 0, |
|
94 | - array(3, 1), |
|
95 | - array(5, 1), |
|
96 | - array(7, 1), |
|
97 | - array(9, 1), |
|
98 | - array(9, 1), |
|
99 | - array(12, 2), |
|
100 | - array(13, 1), |
|
101 | - array(13, 1), |
|
102 | - array(13, 1), |
|
103 | - array(13, 1), |
|
104 | - array(13, 1), |
|
105 | - array(13, 1), |
|
106 | - array(15, 2), |
|
107 | - array(15, 3), |
|
108 | - array(20, 3), |
|
109 | - array(19, 1), |
|
110 | - array(19, 3), |
|
111 | - array(16, 2), |
|
112 | - array(16, 3), |
|
113 | - array(25, 1), |
|
114 | - array(25, 3) |
|
115 | - ); |
|
116 | - |
|
117 | - private $table = array(array(3 => 5, 4 => array(1,12), 5 => 6, 6 => array(1,13), 7 => 3, 8 => array(1,9), 9 => 4, 10 => array(1,10), 11 => array(1,11), 12 => 1, 13 => 2, 15 => 7, 16 => 8, 17 => array(1,14), 23 => array(1,15)), array( 1 => array(3)), array( 14 => array(1,16)), array( 14 => array(2,7), 18 => array(2,7), 22 => array(2,7), 24 => array(2,7)), array( 14 => array(2,8), 18 => array(2,8), 22 => array(2,8), 24 => array(2,8)), array( 14 => array(2,9), 18 => array(2,9), 22 => array(2,9), 24 => array(2,9)), array( 14 => array(2,10), 18 => array(2,10), 22 => array(2,10), 24 => array(2,10)), array( 14 => array(2,11), 18 => array(2,11), 22 => array(2,11), 24 => array(2,11)), array( 14 => array(2,12), 18 => array(2,12), 22 => array(2,12), 24 => array(2,12)), array( 14 => array(2,3), 18 => array(2,3), 22 => array(2,3), 24 => array(2,3)), array( 14 => array(2,4), 18 => array(2,4), 22 => array(2,4), 24 => array(2,4)), array( 14 => array(2,5), 18 => array(2,5), 22 => array(2,5), 24 => array(2,5)), array( 14 => array(2,1), 18 => array(2,1), 21 => array(2,1), 22 => array(2,1), 24 => array(2,1)), array( 14 => array(2,2), 18 => array(2,2), 22 => array(2,2), 24 => array(2,2)), array( 3 => 20, 4 => array(1,12), 18 => array(1,17), 19 => 18, 20 => 19 ), array( 3 => 5, 4 => array(1,12), 5 => 6, 6 => array(1,13), 7 => 3, 8 => array(1,9), 9 => 4, 10 => array(1,10), 11 => array(1,11), 13 => 23, 15 => 7, 16 => 8, 17 => array(1,14), 23 => array(1,15), 24 => array(1,21), 25 => 22 ), array( 1 => array(2,6)), array( 14 => array(2,13), 18 => array(2,13), 22 => array(2,13), 24 => array(2,13)), array( 18 => array(1,24), 22 => array(1,25)), array( 18 => array(2,16), 22 => array(2,16)), array( 21 => array(1,26)), array( 14 => array(2,18), 18 => array(2,18), 22 => array(2,18), 24 => array(2,18)), array( 22 => array(1,28), 24 => array(1,27)), array( 22 => array(2,20), 24 => array(2,20)), array( 14 => array(2,14), 18 => array(2,14), 22 => array(2,14), 24 => array(2,14)), array( 3 => 20, 4 => array(1,12), 20 => 29 ), array( 3 => 5, 4 => array(1,12), 5 => 6, 6 => array(1,13), 7 => 3, 8 => array(1,9), 9 => 4, 10 => array(1,10), 11 => array(1,11), 13 => 30, 15 => 7, 16 => 8, 17 => array(1,14), 23 => array(1,15)), array( 14 => array(2,19), 18 => array(2,19), 22 => array(2,19), 24 => array(2,19)), array( 3 => 5, 4 => array(1,12), 5 => 6, 6 => array(1,13), 7 => 3, 8 => array(1,9), 9 => 4, 10 => array(1,10), 11 => array(1,11), 13 => 31, 15 => 7, 16 => 8, 17 => array(1,14), 23 => array(1,15)), array( 18 => array(2,17), 22 => array(2,17)), array( 18 => array(2,15), 22 => array(2,15)), array( 22 => array(2,21), 24 => array(2,21)), |
|
118 | - ); |
|
119 | - |
|
120 | - private $defaultActions = array( |
|
121 | - 16 => array(2, 6) |
|
122 | - ); |
|
123 | - |
|
124 | - /** |
|
125 | - * @param string $input JSON string |
|
126 | - * @param int $flags Bitmask of parse/lint options (see constants of this class) |
|
127 | - * @return null|ParsingException null if no error is found, a ParsingException containing all details otherwise |
|
128 | - */ |
|
129 | - public function lint($input, $flags = 0) |
|
130 | - { |
|
131 | - try { |
|
132 | - $this->parse($input, $flags); |
|
133 | - } catch (ParsingException $e) { |
|
134 | - return $e; |
|
135 | - } |
|
136 | - return null; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @param string $input JSON string |
|
141 | - * @param int $flags Bitmask of parse/lint options (see constants of this class) |
|
142 | - * @return mixed |
|
143 | - * @throws ParsingException |
|
144 | - */ |
|
145 | - public function parse($input, $flags = 0) |
|
146 | - { |
|
147 | - $this->failOnBOM($input); |
|
148 | - |
|
149 | - $this->flags = $flags; |
|
150 | - |
|
151 | - $this->stack = array(0); |
|
152 | - $this->vstack = array(null); |
|
153 | - $this->lstack = array(); |
|
154 | - |
|
155 | - $yytext = ''; |
|
156 | - $yylineno = 0; |
|
157 | - $yyleng = 0; |
|
158 | - $recovering = 0; |
|
159 | - $TERROR = 2; |
|
160 | - $EOF = 1; |
|
161 | - |
|
162 | - $this->lexer = new Lexer(); |
|
163 | - $this->lexer->setInput($input); |
|
164 | - |
|
165 | - $yyloc = $this->lexer->yylloc; |
|
166 | - $this->lstack[] = $yyloc; |
|
167 | - |
|
168 | - $symbol = null; |
|
169 | - $preErrorSymbol = null; |
|
170 | - $state = null; |
|
171 | - $action = null; |
|
172 | - $a = null; |
|
173 | - $r = null; |
|
174 | - $yyval = new stdClass; |
|
175 | - $p = null; |
|
176 | - $len = null; |
|
177 | - $newState = null; |
|
178 | - $expected = null; |
|
179 | - $errStr = null; |
|
180 | - |
|
181 | - while (true) { |
|
182 | - // retrieve state number from top of stack |
|
183 | - $state = $this->stack[\count($this->stack)-1]; |
|
184 | - |
|
185 | - // use default actions if available |
|
186 | - if (isset($this->defaultActions[$state])) { |
|
187 | - $action = $this->defaultActions[$state]; |
|
188 | - } else { |
|
189 | - if ($symbol == null) { |
|
190 | - $symbol = $this->lex(); |
|
191 | - } |
|
192 | - // read action for current state and first input |
|
193 | - $action = isset($this->table[$state][$symbol]) ? $this->table[$state][$symbol] : false; |
|
194 | - } |
|
195 | - |
|
196 | - // handle parse error |
|
197 | - if (!$action || !$action[0]) { |
|
198 | - if (!$recovering) { |
|
199 | - // Report error |
|
200 | - $expected = array(); |
|
201 | - foreach ($this->table[$state] as $p => $ignore) { |
|
202 | - if (isset($this->terminals_[$p]) && $p > 2) { |
|
203 | - $expected[] = "'" . $this->terminals_[$p] . "'"; |
|
204 | - } |
|
205 | - } |
|
206 | - |
|
207 | - $message = null; |
|
208 | - if (\in_array("'STRING'", $expected) && \in_array(substr($this->lexer->match, 0, 1), array('"', "'"))) { |
|
209 | - $message = "Invalid string"; |
|
210 | - if ("'" === substr($this->lexer->match, 0, 1)) { |
|
211 | - $message .= ", it appears you used single quotes instead of double quotes"; |
|
212 | - } elseif (preg_match('{".+?(\\\\[^"bfnrt/\\\\u](...)?)}', $this->lexer->getFullUpcomingInput(), $match)) { |
|
213 | - $message .= ", it appears you have an unescaped backslash at: ".$match[1]; |
|
214 | - } elseif (preg_match('{"(?:[^"]+|\\\\")*$}m', $this->lexer->getFullUpcomingInput())) { |
|
215 | - $message .= ", it appears you forgot to terminate a string, or attempted to write a multiline string which is invalid"; |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - $errStr = 'Parse error on line ' . ($yylineno+1) . ":\n"; |
|
220 | - $errStr .= $this->lexer->showPosition() . "\n"; |
|
221 | - if ($message) { |
|
222 | - $errStr .= $message; |
|
223 | - } else { |
|
224 | - $errStr .= (\count($expected) > 1) ? "Expected one of: " : "Expected: "; |
|
225 | - $errStr .= implode(', ', $expected); |
|
226 | - } |
|
227 | - |
|
228 | - if (',' === substr(trim($this->lexer->getPastInput()), -1)) { |
|
229 | - $errStr .= " - It appears you have an extra trailing comma"; |
|
230 | - } |
|
231 | - |
|
232 | - $this->parseError($errStr, array( |
|
233 | - 'text' => $this->lexer->match, |
|
234 | - 'token' => !empty($this->terminals_[$symbol]) ? $this->terminals_[$symbol] : $symbol, |
|
235 | - 'line' => $this->lexer->yylineno, |
|
236 | - 'loc' => $yyloc, |
|
237 | - 'expected' => $expected, |
|
238 | - )); |
|
239 | - } |
|
240 | - |
|
241 | - // just recovered from another error |
|
242 | - if ($recovering == 3) { |
|
243 | - if ($symbol == $EOF) { |
|
244 | - throw new ParsingException($errStr ?: 'Parsing halted.'); |
|
245 | - } |
|
246 | - |
|
247 | - // discard current lookahead and grab another |
|
248 | - $yyleng = $this->lexer->yyleng; |
|
249 | - $yytext = $this->lexer->yytext; |
|
250 | - $yylineno = $this->lexer->yylineno; |
|
251 | - $yyloc = $this->lexer->yylloc; |
|
252 | - $symbol = $this->lex(); |
|
253 | - } |
|
254 | - |
|
255 | - // try to recover from error |
|
256 | - while (true) { |
|
257 | - // check for error recovery rule in this state |
|
258 | - if (\array_key_exists($TERROR, $this->table[$state])) { |
|
259 | - break; |
|
260 | - } |
|
261 | - if ($state == 0) { |
|
262 | - throw new ParsingException($errStr ?: 'Parsing halted.'); |
|
263 | - } |
|
264 | - $this->popStack(1); |
|
265 | - $state = $this->stack[\count($this->stack)-1]; |
|
266 | - } |
|
267 | - |
|
268 | - $preErrorSymbol = $symbol; // save the lookahead token |
|
269 | - $symbol = $TERROR; // insert generic error symbol as new lookahead |
|
270 | - $state = $this->stack[\count($this->stack)-1]; |
|
271 | - $action = isset($this->table[$state][$TERROR]) ? $this->table[$state][$TERROR] : false; |
|
272 | - $recovering = 3; // allow 3 real symbols to be shifted before reporting a new error |
|
273 | - } |
|
274 | - |
|
275 | - // this shouldn't happen, unless resolve defaults are off |
|
276 | - if (\is_array($action[0]) && \count($action) > 1) { |
|
277 | - throw new ParsingException('Parse Error: multiple actions possible at state: ' . $state . ', token: ' . $symbol); |
|
278 | - } |
|
279 | - |
|
280 | - switch ($action[0]) { |
|
281 | - case 1: // shift |
|
282 | - $this->stack[] = $symbol; |
|
283 | - $this->vstack[] = $this->lexer->yytext; |
|
284 | - $this->lstack[] = $this->lexer->yylloc; |
|
285 | - $this->stack[] = $action[1]; // push state |
|
286 | - $symbol = null; |
|
287 | - if (!$preErrorSymbol) { // normal execution/no error |
|
288 | - $yyleng = $this->lexer->yyleng; |
|
289 | - $yytext = $this->lexer->yytext; |
|
290 | - $yylineno = $this->lexer->yylineno; |
|
291 | - $yyloc = $this->lexer->yylloc; |
|
292 | - if ($recovering > 0) { |
|
293 | - $recovering--; |
|
294 | - } |
|
295 | - } else { // error just occurred, resume old lookahead f/ before error |
|
296 | - $symbol = $preErrorSymbol; |
|
297 | - $preErrorSymbol = null; |
|
298 | - } |
|
299 | - break; |
|
300 | - |
|
301 | - case 2: // reduce |
|
302 | - $len = $this->productions_[$action[1]][1]; |
|
303 | - |
|
304 | - // perform semantic action |
|
305 | - $yyval->token = $this->vstack[\count($this->vstack) - $len]; // default to $$ = $1 |
|
306 | - // default location, uses first token for firsts, last for lasts |
|
307 | - $yyval->store = array( // _$ = store |
|
308 | - 'first_line' => $this->lstack[\count($this->lstack) - ($len ?: 1)]['first_line'], |
|
309 | - 'last_line' => $this->lstack[\count($this->lstack) - 1]['last_line'], |
|
310 | - 'first_column' => $this->lstack[\count($this->lstack) - ($len ?: 1)]['first_column'], |
|
311 | - 'last_column' => $this->lstack[\count($this->lstack) - 1]['last_column'], |
|
312 | - ); |
|
313 | - $r = $this->performAction($yyval, $yytext, $yyleng, $yylineno, $action[1], $this->vstack); |
|
314 | - |
|
315 | - if (!$r instanceof Undefined) { |
|
316 | - return $r; |
|
317 | - } |
|
318 | - |
|
319 | - if ($len) { |
|
320 | - $this->popStack($len); |
|
321 | - } |
|
322 | - |
|
323 | - $this->stack[] = $this->productions_[$action[1]][0]; // push nonterminal (reduce) |
|
324 | - $this->vstack[] = $yyval->token; |
|
325 | - $this->lstack[] = $yyval->store; |
|
326 | - $newState = $this->table[$this->stack[\count($this->stack)-2]][$this->stack[\count($this->stack)-1]]; |
|
327 | - $this->stack[] = $newState; |
|
328 | - break; |
|
329 | - |
|
330 | - case 3: // accept |
|
331 | - |
|
332 | - return true; |
|
333 | - } |
|
334 | - } |
|
335 | - } |
|
336 | - |
|
337 | - protected function parseError($str, $hash) |
|
338 | - { |
|
339 | - throw new ParsingException($str, $hash); |
|
340 | - } |
|
341 | - |
|
342 | - // $$ = $tokens // needs to be passed by ref? |
|
343 | - // $ = $token |
|
344 | - // _$ removed, useless? |
|
345 | - private function performAction(stdClass $yyval, $yytext, $yyleng, $yylineno, $yystate, &$tokens) |
|
346 | - { |
|
347 | - // $0 = $len |
|
348 | - $len = \count($tokens) - 1; |
|
349 | - switch ($yystate) { |
|
350 | - case 1: |
|
351 | - $yytext = preg_replace_callback('{(?:\\\\["bfnrt/\\\\]|\\\\u[a-fA-F0-9]{4})}', array($this, 'stringInterpolation'), $yytext); |
|
352 | - $yyval->token = $yytext; |
|
353 | - break; |
|
354 | - case 2: |
|
355 | - if (strpos($yytext, 'e') !== false || strpos($yytext, 'E') !== false) { |
|
356 | - $yyval->token = \floatval($yytext); |
|
357 | - } else { |
|
358 | - $yyval->token = strpos($yytext, '.') === false ? \intval($yytext) : \floatval($yytext); |
|
359 | - } |
|
360 | - break; |
|
361 | - case 3: |
|
362 | - $yyval->token = null; |
|
363 | - break; |
|
364 | - case 4: |
|
365 | - $yyval->token = true; |
|
366 | - break; |
|
367 | - case 5: |
|
368 | - $yyval->token = false; |
|
369 | - break; |
|
370 | - case 6: |
|
371 | - return $yyval->token = $tokens[$len-1]; |
|
372 | - case 13: |
|
373 | - if ($this->flags & self::PARSE_TO_ASSOC) { |
|
374 | - $yyval->token = array(); |
|
375 | - } else { |
|
376 | - $yyval->token = new stdClass; |
|
377 | - } |
|
378 | - break; |
|
379 | - case 14: |
|
380 | - $yyval->token = $tokens[$len-1]; |
|
381 | - break; |
|
382 | - case 15: |
|
383 | - $yyval->token = array($tokens[$len-2], $tokens[$len]); |
|
384 | - break; |
|
385 | - case 16: |
|
386 | - if (PHP_VERSION_ID < 70100) { |
|
387 | - $property = $tokens[$len][0] === '' ? '_empty_' : $tokens[$len][0]; |
|
388 | - } else { |
|
389 | - $property = $tokens[$len][0]; |
|
390 | - } |
|
391 | - if ($this->flags & self::PARSE_TO_ASSOC) { |
|
392 | - $yyval->token = array(); |
|
393 | - $yyval->token[$property] = $tokens[$len][1]; |
|
394 | - } else { |
|
395 | - $yyval->token = new stdClass; |
|
396 | - $yyval->token->$property = $tokens[$len][1]; |
|
397 | - } |
|
398 | - break; |
|
399 | - case 17: |
|
400 | - if ($this->flags & self::PARSE_TO_ASSOC) { |
|
401 | - $yyval->token =& $tokens[$len-2]; |
|
402 | - $key = $tokens[$len][0]; |
|
403 | - if (($this->flags & self::DETECT_KEY_CONFLICTS) && isset($tokens[$len-2][$key])) { |
|
404 | - $errStr = 'Parse error on line ' . ($yylineno+1) . ":\n"; |
|
405 | - $errStr .= $this->lexer->showPosition() . "\n"; |
|
406 | - $errStr .= "Duplicate key: ".$tokens[$len][0]; |
|
407 | - throw new DuplicateKeyException($errStr, $tokens[$len][0], array('line' => $yylineno+1)); |
|
408 | - } elseif (($this->flags & self::ALLOW_DUPLICATE_KEYS) && isset($tokens[$len-2][$key])) { |
|
409 | - $duplicateCount = 1; |
|
410 | - do { |
|
411 | - $duplicateKey = $key . '.' . $duplicateCount++; |
|
412 | - } while (isset($tokens[$len-2][$duplicateKey])); |
|
413 | - $key = $duplicateKey; |
|
414 | - } |
|
415 | - $tokens[$len-2][$key] = $tokens[$len][1]; |
|
416 | - } else { |
|
417 | - $yyval->token = $tokens[$len-2]; |
|
418 | - if (PHP_VERSION_ID < 70100) { |
|
419 | - $key = $tokens[$len][0] === '' ? '_empty_' : $tokens[$len][0]; |
|
420 | - } else { |
|
421 | - $key = $tokens[$len][0]; |
|
422 | - } |
|
423 | - if (($this->flags & self::DETECT_KEY_CONFLICTS) && isset($tokens[$len-2]->{$key})) { |
|
424 | - $errStr = 'Parse error on line ' . ($yylineno+1) . ":\n"; |
|
425 | - $errStr .= $this->lexer->showPosition() . "\n"; |
|
426 | - $errStr .= "Duplicate key: ".$tokens[$len][0]; |
|
427 | - throw new DuplicateKeyException($errStr, $tokens[$len][0], array('line' => $yylineno+1)); |
|
428 | - } elseif (($this->flags & self::ALLOW_DUPLICATE_KEYS) && isset($tokens[$len-2]->{$key})) { |
|
429 | - $duplicateCount = 1; |
|
430 | - do { |
|
431 | - $duplicateKey = $key . '.' . $duplicateCount++; |
|
432 | - } while (isset($tokens[$len-2]->$duplicateKey)); |
|
433 | - $key = $duplicateKey; |
|
434 | - } |
|
435 | - $tokens[$len-2]->$key = $tokens[$len][1]; |
|
436 | - } |
|
437 | - break; |
|
438 | - case 18: |
|
439 | - $yyval->token = array(); |
|
440 | - break; |
|
441 | - case 19: |
|
442 | - $yyval->token = $tokens[$len-1]; |
|
443 | - break; |
|
444 | - case 20: |
|
445 | - $yyval->token = array($tokens[$len]); |
|
446 | - break; |
|
447 | - case 21: |
|
448 | - $tokens[$len-2][] = $tokens[$len]; |
|
449 | - $yyval->token = $tokens[$len-2]; |
|
450 | - break; |
|
451 | - } |
|
452 | - |
|
453 | - return new Undefined(); |
|
454 | - } |
|
455 | - |
|
456 | - private function stringInterpolation($match) |
|
457 | - { |
|
458 | - switch ($match[0]) { |
|
459 | - case '\\\\': |
|
460 | - return '\\'; |
|
461 | - case '\"': |
|
462 | - return '"'; |
|
463 | - case '\b': |
|
464 | - return \chr(8); |
|
465 | - case '\f': |
|
466 | - return \chr(12); |
|
467 | - case '\n': |
|
468 | - return "\n"; |
|
469 | - case '\r': |
|
470 | - return "\r"; |
|
471 | - case '\t': |
|
472 | - return "\t"; |
|
473 | - case '\/': |
|
474 | - return "/"; |
|
475 | - default: |
|
476 | - return html_entity_decode('&#x'.ltrim(substr($match[0], 2), '0').';', ENT_QUOTES, 'UTF-8'); |
|
477 | - } |
|
478 | - } |
|
479 | - |
|
480 | - private function popStack($n) |
|
481 | - { |
|
482 | - $this->stack = \array_slice($this->stack, 0, - (2 * $n)); |
|
483 | - $this->vstack = \array_slice($this->vstack, 0, - $n); |
|
484 | - $this->lstack = \array_slice($this->lstack, 0, - $n); |
|
485 | - } |
|
486 | - |
|
487 | - private function lex() |
|
488 | - { |
|
489 | - $token = $this->lexer->lex() ?: 1; // $end = 1 |
|
490 | - // if token isn't its numeric value, convert |
|
491 | - if (!is_numeric($token)) { |
|
492 | - $token = isset($this->symbols[$token]) ? $this->symbols[$token] : $token; |
|
493 | - } |
|
494 | - |
|
495 | - return $token; |
|
496 | - } |
|
497 | - |
|
498 | - private function failOnBOM($input) |
|
499 | - { |
|
500 | - // UTF-8 ByteOrderMark sequence |
|
501 | - $bom = "\xEF\xBB\xBF"; |
|
502 | - |
|
503 | - if (substr($input, 0, 3) === $bom) { |
|
504 | - $this->parseError("BOM detected, make sure your input does not include a Unicode Byte-Order-Mark", array()); |
|
505 | - } |
|
506 | - } |
|
30 | + const DETECT_KEY_CONFLICTS = 1; |
|
31 | + const ALLOW_DUPLICATE_KEYS = 2; |
|
32 | + const PARSE_TO_ASSOC = 4; |
|
33 | + |
|
34 | + private $lexer; |
|
35 | + |
|
36 | + private $flags; |
|
37 | + private $stack; |
|
38 | + private $vstack; // semantic value stack |
|
39 | + private $lstack; // location stack |
|
40 | + |
|
41 | + /** |
|
42 | + * @phpstan-var array<string, int> |
|
43 | + */ |
|
44 | + private $symbols = array( |
|
45 | + 'error' => 2, |
|
46 | + 'JSONString' => 3, |
|
47 | + 'STRING' => 4, |
|
48 | + 'JSONNumber' => 5, |
|
49 | + 'NUMBER' => 6, |
|
50 | + 'JSONNullLiteral' => 7, |
|
51 | + 'NULL' => 8, |
|
52 | + 'JSONBooleanLiteral' => 9, |
|
53 | + 'TRUE' => 10, |
|
54 | + 'FALSE' => 11, |
|
55 | + 'JSONText' => 12, |
|
56 | + 'JSONValue' => 13, |
|
57 | + 'EOF' => 14, |
|
58 | + 'JSONObject' => 15, |
|
59 | + 'JSONArray' => 16, |
|
60 | + '{' => 17, |
|
61 | + '}' => 18, |
|
62 | + 'JSONMemberList' => 19, |
|
63 | + 'JSONMember' => 20, |
|
64 | + ':' => 21, |
|
65 | + ',' => 22, |
|
66 | + '[' => 23, |
|
67 | + ']' => 24, |
|
68 | + 'JSONElementList' => 25, |
|
69 | + '$accept' => 0, |
|
70 | + '$end' => 1, |
|
71 | + ); |
|
72 | + |
|
73 | + /** |
|
74 | + * @phpstan-var array<int, string> |
|
75 | + */ |
|
76 | + private $terminals_ = array( |
|
77 | + 2 => "error", |
|
78 | + 4 => "STRING", |
|
79 | + 6 => "NUMBER", |
|
80 | + 8 => "NULL", |
|
81 | + 10 => "TRUE", |
|
82 | + 11 => "FALSE", |
|
83 | + 14 => "EOF", |
|
84 | + 17 => "{", |
|
85 | + 18 => "}", |
|
86 | + 21 => ":", |
|
87 | + 22 => ",", |
|
88 | + 23 => "[", |
|
89 | + 24 => "]", |
|
90 | + ); |
|
91 | + |
|
92 | + private $productions_ = array( |
|
93 | + 0, |
|
94 | + array(3, 1), |
|
95 | + array(5, 1), |
|
96 | + array(7, 1), |
|
97 | + array(9, 1), |
|
98 | + array(9, 1), |
|
99 | + array(12, 2), |
|
100 | + array(13, 1), |
|
101 | + array(13, 1), |
|
102 | + array(13, 1), |
|
103 | + array(13, 1), |
|
104 | + array(13, 1), |
|
105 | + array(13, 1), |
|
106 | + array(15, 2), |
|
107 | + array(15, 3), |
|
108 | + array(20, 3), |
|
109 | + array(19, 1), |
|
110 | + array(19, 3), |
|
111 | + array(16, 2), |
|
112 | + array(16, 3), |
|
113 | + array(25, 1), |
|
114 | + array(25, 3) |
|
115 | + ); |
|
116 | + |
|
117 | + private $table = array(array(3 => 5, 4 => array(1,12), 5 => 6, 6 => array(1,13), 7 => 3, 8 => array(1,9), 9 => 4, 10 => array(1,10), 11 => array(1,11), 12 => 1, 13 => 2, 15 => 7, 16 => 8, 17 => array(1,14), 23 => array(1,15)), array( 1 => array(3)), array( 14 => array(1,16)), array( 14 => array(2,7), 18 => array(2,7), 22 => array(2,7), 24 => array(2,7)), array( 14 => array(2,8), 18 => array(2,8), 22 => array(2,8), 24 => array(2,8)), array( 14 => array(2,9), 18 => array(2,9), 22 => array(2,9), 24 => array(2,9)), array( 14 => array(2,10), 18 => array(2,10), 22 => array(2,10), 24 => array(2,10)), array( 14 => array(2,11), 18 => array(2,11), 22 => array(2,11), 24 => array(2,11)), array( 14 => array(2,12), 18 => array(2,12), 22 => array(2,12), 24 => array(2,12)), array( 14 => array(2,3), 18 => array(2,3), 22 => array(2,3), 24 => array(2,3)), array( 14 => array(2,4), 18 => array(2,4), 22 => array(2,4), 24 => array(2,4)), array( 14 => array(2,5), 18 => array(2,5), 22 => array(2,5), 24 => array(2,5)), array( 14 => array(2,1), 18 => array(2,1), 21 => array(2,1), 22 => array(2,1), 24 => array(2,1)), array( 14 => array(2,2), 18 => array(2,2), 22 => array(2,2), 24 => array(2,2)), array( 3 => 20, 4 => array(1,12), 18 => array(1,17), 19 => 18, 20 => 19 ), array( 3 => 5, 4 => array(1,12), 5 => 6, 6 => array(1,13), 7 => 3, 8 => array(1,9), 9 => 4, 10 => array(1,10), 11 => array(1,11), 13 => 23, 15 => 7, 16 => 8, 17 => array(1,14), 23 => array(1,15), 24 => array(1,21), 25 => 22 ), array( 1 => array(2,6)), array( 14 => array(2,13), 18 => array(2,13), 22 => array(2,13), 24 => array(2,13)), array( 18 => array(1,24), 22 => array(1,25)), array( 18 => array(2,16), 22 => array(2,16)), array( 21 => array(1,26)), array( 14 => array(2,18), 18 => array(2,18), 22 => array(2,18), 24 => array(2,18)), array( 22 => array(1,28), 24 => array(1,27)), array( 22 => array(2,20), 24 => array(2,20)), array( 14 => array(2,14), 18 => array(2,14), 22 => array(2,14), 24 => array(2,14)), array( 3 => 20, 4 => array(1,12), 20 => 29 ), array( 3 => 5, 4 => array(1,12), 5 => 6, 6 => array(1,13), 7 => 3, 8 => array(1,9), 9 => 4, 10 => array(1,10), 11 => array(1,11), 13 => 30, 15 => 7, 16 => 8, 17 => array(1,14), 23 => array(1,15)), array( 14 => array(2,19), 18 => array(2,19), 22 => array(2,19), 24 => array(2,19)), array( 3 => 5, 4 => array(1,12), 5 => 6, 6 => array(1,13), 7 => 3, 8 => array(1,9), 9 => 4, 10 => array(1,10), 11 => array(1,11), 13 => 31, 15 => 7, 16 => 8, 17 => array(1,14), 23 => array(1,15)), array( 18 => array(2,17), 22 => array(2,17)), array( 18 => array(2,15), 22 => array(2,15)), array( 22 => array(2,21), 24 => array(2,21)), |
|
118 | + ); |
|
119 | + |
|
120 | + private $defaultActions = array( |
|
121 | + 16 => array(2, 6) |
|
122 | + ); |
|
123 | + |
|
124 | + /** |
|
125 | + * @param string $input JSON string |
|
126 | + * @param int $flags Bitmask of parse/lint options (see constants of this class) |
|
127 | + * @return null|ParsingException null if no error is found, a ParsingException containing all details otherwise |
|
128 | + */ |
|
129 | + public function lint($input, $flags = 0) |
|
130 | + { |
|
131 | + try { |
|
132 | + $this->parse($input, $flags); |
|
133 | + } catch (ParsingException $e) { |
|
134 | + return $e; |
|
135 | + } |
|
136 | + return null; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @param string $input JSON string |
|
141 | + * @param int $flags Bitmask of parse/lint options (see constants of this class) |
|
142 | + * @return mixed |
|
143 | + * @throws ParsingException |
|
144 | + */ |
|
145 | + public function parse($input, $flags = 0) |
|
146 | + { |
|
147 | + $this->failOnBOM($input); |
|
148 | + |
|
149 | + $this->flags = $flags; |
|
150 | + |
|
151 | + $this->stack = array(0); |
|
152 | + $this->vstack = array(null); |
|
153 | + $this->lstack = array(); |
|
154 | + |
|
155 | + $yytext = ''; |
|
156 | + $yylineno = 0; |
|
157 | + $yyleng = 0; |
|
158 | + $recovering = 0; |
|
159 | + $TERROR = 2; |
|
160 | + $EOF = 1; |
|
161 | + |
|
162 | + $this->lexer = new Lexer(); |
|
163 | + $this->lexer->setInput($input); |
|
164 | + |
|
165 | + $yyloc = $this->lexer->yylloc; |
|
166 | + $this->lstack[] = $yyloc; |
|
167 | + |
|
168 | + $symbol = null; |
|
169 | + $preErrorSymbol = null; |
|
170 | + $state = null; |
|
171 | + $action = null; |
|
172 | + $a = null; |
|
173 | + $r = null; |
|
174 | + $yyval = new stdClass; |
|
175 | + $p = null; |
|
176 | + $len = null; |
|
177 | + $newState = null; |
|
178 | + $expected = null; |
|
179 | + $errStr = null; |
|
180 | + |
|
181 | + while (true) { |
|
182 | + // retrieve state number from top of stack |
|
183 | + $state = $this->stack[\count($this->stack)-1]; |
|
184 | + |
|
185 | + // use default actions if available |
|
186 | + if (isset($this->defaultActions[$state])) { |
|
187 | + $action = $this->defaultActions[$state]; |
|
188 | + } else { |
|
189 | + if ($symbol == null) { |
|
190 | + $symbol = $this->lex(); |
|
191 | + } |
|
192 | + // read action for current state and first input |
|
193 | + $action = isset($this->table[$state][$symbol]) ? $this->table[$state][$symbol] : false; |
|
194 | + } |
|
195 | + |
|
196 | + // handle parse error |
|
197 | + if (!$action || !$action[0]) { |
|
198 | + if (!$recovering) { |
|
199 | + // Report error |
|
200 | + $expected = array(); |
|
201 | + foreach ($this->table[$state] as $p => $ignore) { |
|
202 | + if (isset($this->terminals_[$p]) && $p > 2) { |
|
203 | + $expected[] = "'" . $this->terminals_[$p] . "'"; |
|
204 | + } |
|
205 | + } |
|
206 | + |
|
207 | + $message = null; |
|
208 | + if (\in_array("'STRING'", $expected) && \in_array(substr($this->lexer->match, 0, 1), array('"', "'"))) { |
|
209 | + $message = "Invalid string"; |
|
210 | + if ("'" === substr($this->lexer->match, 0, 1)) { |
|
211 | + $message .= ", it appears you used single quotes instead of double quotes"; |
|
212 | + } elseif (preg_match('{".+?(\\\\[^"bfnrt/\\\\u](...)?)}', $this->lexer->getFullUpcomingInput(), $match)) { |
|
213 | + $message .= ", it appears you have an unescaped backslash at: ".$match[1]; |
|
214 | + } elseif (preg_match('{"(?:[^"]+|\\\\")*$}m', $this->lexer->getFullUpcomingInput())) { |
|
215 | + $message .= ", it appears you forgot to terminate a string, or attempted to write a multiline string which is invalid"; |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + $errStr = 'Parse error on line ' . ($yylineno+1) . ":\n"; |
|
220 | + $errStr .= $this->lexer->showPosition() . "\n"; |
|
221 | + if ($message) { |
|
222 | + $errStr .= $message; |
|
223 | + } else { |
|
224 | + $errStr .= (\count($expected) > 1) ? "Expected one of: " : "Expected: "; |
|
225 | + $errStr .= implode(', ', $expected); |
|
226 | + } |
|
227 | + |
|
228 | + if (',' === substr(trim($this->lexer->getPastInput()), -1)) { |
|
229 | + $errStr .= " - It appears you have an extra trailing comma"; |
|
230 | + } |
|
231 | + |
|
232 | + $this->parseError($errStr, array( |
|
233 | + 'text' => $this->lexer->match, |
|
234 | + 'token' => !empty($this->terminals_[$symbol]) ? $this->terminals_[$symbol] : $symbol, |
|
235 | + 'line' => $this->lexer->yylineno, |
|
236 | + 'loc' => $yyloc, |
|
237 | + 'expected' => $expected, |
|
238 | + )); |
|
239 | + } |
|
240 | + |
|
241 | + // just recovered from another error |
|
242 | + if ($recovering == 3) { |
|
243 | + if ($symbol == $EOF) { |
|
244 | + throw new ParsingException($errStr ?: 'Parsing halted.'); |
|
245 | + } |
|
246 | + |
|
247 | + // discard current lookahead and grab another |
|
248 | + $yyleng = $this->lexer->yyleng; |
|
249 | + $yytext = $this->lexer->yytext; |
|
250 | + $yylineno = $this->lexer->yylineno; |
|
251 | + $yyloc = $this->lexer->yylloc; |
|
252 | + $symbol = $this->lex(); |
|
253 | + } |
|
254 | + |
|
255 | + // try to recover from error |
|
256 | + while (true) { |
|
257 | + // check for error recovery rule in this state |
|
258 | + if (\array_key_exists($TERROR, $this->table[$state])) { |
|
259 | + break; |
|
260 | + } |
|
261 | + if ($state == 0) { |
|
262 | + throw new ParsingException($errStr ?: 'Parsing halted.'); |
|
263 | + } |
|
264 | + $this->popStack(1); |
|
265 | + $state = $this->stack[\count($this->stack)-1]; |
|
266 | + } |
|
267 | + |
|
268 | + $preErrorSymbol = $symbol; // save the lookahead token |
|
269 | + $symbol = $TERROR; // insert generic error symbol as new lookahead |
|
270 | + $state = $this->stack[\count($this->stack)-1]; |
|
271 | + $action = isset($this->table[$state][$TERROR]) ? $this->table[$state][$TERROR] : false; |
|
272 | + $recovering = 3; // allow 3 real symbols to be shifted before reporting a new error |
|
273 | + } |
|
274 | + |
|
275 | + // this shouldn't happen, unless resolve defaults are off |
|
276 | + if (\is_array($action[0]) && \count($action) > 1) { |
|
277 | + throw new ParsingException('Parse Error: multiple actions possible at state: ' . $state . ', token: ' . $symbol); |
|
278 | + } |
|
279 | + |
|
280 | + switch ($action[0]) { |
|
281 | + case 1: // shift |
|
282 | + $this->stack[] = $symbol; |
|
283 | + $this->vstack[] = $this->lexer->yytext; |
|
284 | + $this->lstack[] = $this->lexer->yylloc; |
|
285 | + $this->stack[] = $action[1]; // push state |
|
286 | + $symbol = null; |
|
287 | + if (!$preErrorSymbol) { // normal execution/no error |
|
288 | + $yyleng = $this->lexer->yyleng; |
|
289 | + $yytext = $this->lexer->yytext; |
|
290 | + $yylineno = $this->lexer->yylineno; |
|
291 | + $yyloc = $this->lexer->yylloc; |
|
292 | + if ($recovering > 0) { |
|
293 | + $recovering--; |
|
294 | + } |
|
295 | + } else { // error just occurred, resume old lookahead f/ before error |
|
296 | + $symbol = $preErrorSymbol; |
|
297 | + $preErrorSymbol = null; |
|
298 | + } |
|
299 | + break; |
|
300 | + |
|
301 | + case 2: // reduce |
|
302 | + $len = $this->productions_[$action[1]][1]; |
|
303 | + |
|
304 | + // perform semantic action |
|
305 | + $yyval->token = $this->vstack[\count($this->vstack) - $len]; // default to $$ = $1 |
|
306 | + // default location, uses first token for firsts, last for lasts |
|
307 | + $yyval->store = array( // _$ = store |
|
308 | + 'first_line' => $this->lstack[\count($this->lstack) - ($len ?: 1)]['first_line'], |
|
309 | + 'last_line' => $this->lstack[\count($this->lstack) - 1]['last_line'], |
|
310 | + 'first_column' => $this->lstack[\count($this->lstack) - ($len ?: 1)]['first_column'], |
|
311 | + 'last_column' => $this->lstack[\count($this->lstack) - 1]['last_column'], |
|
312 | + ); |
|
313 | + $r = $this->performAction($yyval, $yytext, $yyleng, $yylineno, $action[1], $this->vstack); |
|
314 | + |
|
315 | + if (!$r instanceof Undefined) { |
|
316 | + return $r; |
|
317 | + } |
|
318 | + |
|
319 | + if ($len) { |
|
320 | + $this->popStack($len); |
|
321 | + } |
|
322 | + |
|
323 | + $this->stack[] = $this->productions_[$action[1]][0]; // push nonterminal (reduce) |
|
324 | + $this->vstack[] = $yyval->token; |
|
325 | + $this->lstack[] = $yyval->store; |
|
326 | + $newState = $this->table[$this->stack[\count($this->stack)-2]][$this->stack[\count($this->stack)-1]]; |
|
327 | + $this->stack[] = $newState; |
|
328 | + break; |
|
329 | + |
|
330 | + case 3: // accept |
|
331 | + |
|
332 | + return true; |
|
333 | + } |
|
334 | + } |
|
335 | + } |
|
336 | + |
|
337 | + protected function parseError($str, $hash) |
|
338 | + { |
|
339 | + throw new ParsingException($str, $hash); |
|
340 | + } |
|
341 | + |
|
342 | + // $$ = $tokens // needs to be passed by ref? |
|
343 | + // $ = $token |
|
344 | + // _$ removed, useless? |
|
345 | + private function performAction(stdClass $yyval, $yytext, $yyleng, $yylineno, $yystate, &$tokens) |
|
346 | + { |
|
347 | + // $0 = $len |
|
348 | + $len = \count($tokens) - 1; |
|
349 | + switch ($yystate) { |
|
350 | + case 1: |
|
351 | + $yytext = preg_replace_callback('{(?:\\\\["bfnrt/\\\\]|\\\\u[a-fA-F0-9]{4})}', array($this, 'stringInterpolation'), $yytext); |
|
352 | + $yyval->token = $yytext; |
|
353 | + break; |
|
354 | + case 2: |
|
355 | + if (strpos($yytext, 'e') !== false || strpos($yytext, 'E') !== false) { |
|
356 | + $yyval->token = \floatval($yytext); |
|
357 | + } else { |
|
358 | + $yyval->token = strpos($yytext, '.') === false ? \intval($yytext) : \floatval($yytext); |
|
359 | + } |
|
360 | + break; |
|
361 | + case 3: |
|
362 | + $yyval->token = null; |
|
363 | + break; |
|
364 | + case 4: |
|
365 | + $yyval->token = true; |
|
366 | + break; |
|
367 | + case 5: |
|
368 | + $yyval->token = false; |
|
369 | + break; |
|
370 | + case 6: |
|
371 | + return $yyval->token = $tokens[$len-1]; |
|
372 | + case 13: |
|
373 | + if ($this->flags & self::PARSE_TO_ASSOC) { |
|
374 | + $yyval->token = array(); |
|
375 | + } else { |
|
376 | + $yyval->token = new stdClass; |
|
377 | + } |
|
378 | + break; |
|
379 | + case 14: |
|
380 | + $yyval->token = $tokens[$len-1]; |
|
381 | + break; |
|
382 | + case 15: |
|
383 | + $yyval->token = array($tokens[$len-2], $tokens[$len]); |
|
384 | + break; |
|
385 | + case 16: |
|
386 | + if (PHP_VERSION_ID < 70100) { |
|
387 | + $property = $tokens[$len][0] === '' ? '_empty_' : $tokens[$len][0]; |
|
388 | + } else { |
|
389 | + $property = $tokens[$len][0]; |
|
390 | + } |
|
391 | + if ($this->flags & self::PARSE_TO_ASSOC) { |
|
392 | + $yyval->token = array(); |
|
393 | + $yyval->token[$property] = $tokens[$len][1]; |
|
394 | + } else { |
|
395 | + $yyval->token = new stdClass; |
|
396 | + $yyval->token->$property = $tokens[$len][1]; |
|
397 | + } |
|
398 | + break; |
|
399 | + case 17: |
|
400 | + if ($this->flags & self::PARSE_TO_ASSOC) { |
|
401 | + $yyval->token =& $tokens[$len-2]; |
|
402 | + $key = $tokens[$len][0]; |
|
403 | + if (($this->flags & self::DETECT_KEY_CONFLICTS) && isset($tokens[$len-2][$key])) { |
|
404 | + $errStr = 'Parse error on line ' . ($yylineno+1) . ":\n"; |
|
405 | + $errStr .= $this->lexer->showPosition() . "\n"; |
|
406 | + $errStr .= "Duplicate key: ".$tokens[$len][0]; |
|
407 | + throw new DuplicateKeyException($errStr, $tokens[$len][0], array('line' => $yylineno+1)); |
|
408 | + } elseif (($this->flags & self::ALLOW_DUPLICATE_KEYS) && isset($tokens[$len-2][$key])) { |
|
409 | + $duplicateCount = 1; |
|
410 | + do { |
|
411 | + $duplicateKey = $key . '.' . $duplicateCount++; |
|
412 | + } while (isset($tokens[$len-2][$duplicateKey])); |
|
413 | + $key = $duplicateKey; |
|
414 | + } |
|
415 | + $tokens[$len-2][$key] = $tokens[$len][1]; |
|
416 | + } else { |
|
417 | + $yyval->token = $tokens[$len-2]; |
|
418 | + if (PHP_VERSION_ID < 70100) { |
|
419 | + $key = $tokens[$len][0] === '' ? '_empty_' : $tokens[$len][0]; |
|
420 | + } else { |
|
421 | + $key = $tokens[$len][0]; |
|
422 | + } |
|
423 | + if (($this->flags & self::DETECT_KEY_CONFLICTS) && isset($tokens[$len-2]->{$key})) { |
|
424 | + $errStr = 'Parse error on line ' . ($yylineno+1) . ":\n"; |
|
425 | + $errStr .= $this->lexer->showPosition() . "\n"; |
|
426 | + $errStr .= "Duplicate key: ".$tokens[$len][0]; |
|
427 | + throw new DuplicateKeyException($errStr, $tokens[$len][0], array('line' => $yylineno+1)); |
|
428 | + } elseif (($this->flags & self::ALLOW_DUPLICATE_KEYS) && isset($tokens[$len-2]->{$key})) { |
|
429 | + $duplicateCount = 1; |
|
430 | + do { |
|
431 | + $duplicateKey = $key . '.' . $duplicateCount++; |
|
432 | + } while (isset($tokens[$len-2]->$duplicateKey)); |
|
433 | + $key = $duplicateKey; |
|
434 | + } |
|
435 | + $tokens[$len-2]->$key = $tokens[$len][1]; |
|
436 | + } |
|
437 | + break; |
|
438 | + case 18: |
|
439 | + $yyval->token = array(); |
|
440 | + break; |
|
441 | + case 19: |
|
442 | + $yyval->token = $tokens[$len-1]; |
|
443 | + break; |
|
444 | + case 20: |
|
445 | + $yyval->token = array($tokens[$len]); |
|
446 | + break; |
|
447 | + case 21: |
|
448 | + $tokens[$len-2][] = $tokens[$len]; |
|
449 | + $yyval->token = $tokens[$len-2]; |
|
450 | + break; |
|
451 | + } |
|
452 | + |
|
453 | + return new Undefined(); |
|
454 | + } |
|
455 | + |
|
456 | + private function stringInterpolation($match) |
|
457 | + { |
|
458 | + switch ($match[0]) { |
|
459 | + case '\\\\': |
|
460 | + return '\\'; |
|
461 | + case '\"': |
|
462 | + return '"'; |
|
463 | + case '\b': |
|
464 | + return \chr(8); |
|
465 | + case '\f': |
|
466 | + return \chr(12); |
|
467 | + case '\n': |
|
468 | + return "\n"; |
|
469 | + case '\r': |
|
470 | + return "\r"; |
|
471 | + case '\t': |
|
472 | + return "\t"; |
|
473 | + case '\/': |
|
474 | + return "/"; |
|
475 | + default: |
|
476 | + return html_entity_decode('&#x'.ltrim(substr($match[0], 2), '0').';', ENT_QUOTES, 'UTF-8'); |
|
477 | + } |
|
478 | + } |
|
479 | + |
|
480 | + private function popStack($n) |
|
481 | + { |
|
482 | + $this->stack = \array_slice($this->stack, 0, - (2 * $n)); |
|
483 | + $this->vstack = \array_slice($this->vstack, 0, - $n); |
|
484 | + $this->lstack = \array_slice($this->lstack, 0, - $n); |
|
485 | + } |
|
486 | + |
|
487 | + private function lex() |
|
488 | + { |
|
489 | + $token = $this->lexer->lex() ?: 1; // $end = 1 |
|
490 | + // if token isn't its numeric value, convert |
|
491 | + if (!is_numeric($token)) { |
|
492 | + $token = isset($this->symbols[$token]) ? $this->symbols[$token] : $token; |
|
493 | + } |
|
494 | + |
|
495 | + return $token; |
|
496 | + } |
|
497 | + |
|
498 | + private function failOnBOM($input) |
|
499 | + { |
|
500 | + // UTF-8 ByteOrderMark sequence |
|
501 | + $bom = "\xEF\xBB\xBF"; |
|
502 | + |
|
503 | + if (substr($input, 0, 3) === $bom) { |
|
504 | + $this->parseError("BOM detected, make sure your input does not include a Unicode Byte-Order-Mark", array()); |
|
505 | + } |
|
506 | + } |
|
507 | 507 | } |
@@ -347,107 +347,107 @@ discard block |
||
347 | 347 | // $0 = $len |
348 | 348 | $len = \count($tokens) - 1; |
349 | 349 | switch ($yystate) { |
350 | - case 1: |
|
351 | - $yytext = preg_replace_callback('{(?:\\\\["bfnrt/\\\\]|\\\\u[a-fA-F0-9]{4})}', array($this, 'stringInterpolation'), $yytext); |
|
352 | - $yyval->token = $yytext; |
|
353 | - break; |
|
354 | - case 2: |
|
355 | - if (strpos($yytext, 'e') !== false || strpos($yytext, 'E') !== false) { |
|
356 | - $yyval->token = \floatval($yytext); |
|
357 | - } else { |
|
358 | - $yyval->token = strpos($yytext, '.') === false ? \intval($yytext) : \floatval($yytext); |
|
359 | - } |
|
360 | - break; |
|
361 | - case 3: |
|
362 | - $yyval->token = null; |
|
363 | - break; |
|
364 | - case 4: |
|
365 | - $yyval->token = true; |
|
366 | - break; |
|
367 | - case 5: |
|
368 | - $yyval->token = false; |
|
369 | - break; |
|
370 | - case 6: |
|
371 | - return $yyval->token = $tokens[$len-1]; |
|
372 | - case 13: |
|
373 | - if ($this->flags & self::PARSE_TO_ASSOC) { |
|
374 | - $yyval->token = array(); |
|
375 | - } else { |
|
376 | - $yyval->token = new stdClass; |
|
377 | - } |
|
378 | - break; |
|
379 | - case 14: |
|
380 | - $yyval->token = $tokens[$len-1]; |
|
381 | - break; |
|
382 | - case 15: |
|
383 | - $yyval->token = array($tokens[$len-2], $tokens[$len]); |
|
384 | - break; |
|
385 | - case 16: |
|
386 | - if (PHP_VERSION_ID < 70100) { |
|
387 | - $property = $tokens[$len][0] === '' ? '_empty_' : $tokens[$len][0]; |
|
388 | - } else { |
|
389 | - $property = $tokens[$len][0]; |
|
390 | - } |
|
391 | - if ($this->flags & self::PARSE_TO_ASSOC) { |
|
392 | - $yyval->token = array(); |
|
393 | - $yyval->token[$property] = $tokens[$len][1]; |
|
394 | - } else { |
|
395 | - $yyval->token = new stdClass; |
|
396 | - $yyval->token->$property = $tokens[$len][1]; |
|
397 | - } |
|
398 | - break; |
|
399 | - case 17: |
|
400 | - if ($this->flags & self::PARSE_TO_ASSOC) { |
|
401 | - $yyval->token =& $tokens[$len-2]; |
|
402 | - $key = $tokens[$len][0]; |
|
403 | - if (($this->flags & self::DETECT_KEY_CONFLICTS) && isset($tokens[$len-2][$key])) { |
|
404 | - $errStr = 'Parse error on line ' . ($yylineno+1) . ":\n"; |
|
405 | - $errStr .= $this->lexer->showPosition() . "\n"; |
|
406 | - $errStr .= "Duplicate key: ".$tokens[$len][0]; |
|
407 | - throw new DuplicateKeyException($errStr, $tokens[$len][0], array('line' => $yylineno+1)); |
|
408 | - } elseif (($this->flags & self::ALLOW_DUPLICATE_KEYS) && isset($tokens[$len-2][$key])) { |
|
409 | - $duplicateCount = 1; |
|
410 | - do { |
|
411 | - $duplicateKey = $key . '.' . $duplicateCount++; |
|
412 | - } while (isset($tokens[$len-2][$duplicateKey])); |
|
413 | - $key = $duplicateKey; |
|
414 | - } |
|
415 | - $tokens[$len-2][$key] = $tokens[$len][1]; |
|
416 | - } else { |
|
417 | - $yyval->token = $tokens[$len-2]; |
|
418 | - if (PHP_VERSION_ID < 70100) { |
|
419 | - $key = $tokens[$len][0] === '' ? '_empty_' : $tokens[$len][0]; |
|
420 | - } else { |
|
421 | - $key = $tokens[$len][0]; |
|
422 | - } |
|
423 | - if (($this->flags & self::DETECT_KEY_CONFLICTS) && isset($tokens[$len-2]->{$key})) { |
|
424 | - $errStr = 'Parse error on line ' . ($yylineno+1) . ":\n"; |
|
425 | - $errStr .= $this->lexer->showPosition() . "\n"; |
|
426 | - $errStr .= "Duplicate key: ".$tokens[$len][0]; |
|
427 | - throw new DuplicateKeyException($errStr, $tokens[$len][0], array('line' => $yylineno+1)); |
|
428 | - } elseif (($this->flags & self::ALLOW_DUPLICATE_KEYS) && isset($tokens[$len-2]->{$key})) { |
|
429 | - $duplicateCount = 1; |
|
430 | - do { |
|
431 | - $duplicateKey = $key . '.' . $duplicateCount++; |
|
432 | - } while (isset($tokens[$len-2]->$duplicateKey)); |
|
433 | - $key = $duplicateKey; |
|
434 | - } |
|
435 | - $tokens[$len-2]->$key = $tokens[$len][1]; |
|
436 | - } |
|
437 | - break; |
|
438 | - case 18: |
|
439 | - $yyval->token = array(); |
|
440 | - break; |
|
441 | - case 19: |
|
442 | - $yyval->token = $tokens[$len-1]; |
|
443 | - break; |
|
444 | - case 20: |
|
445 | - $yyval->token = array($tokens[$len]); |
|
446 | - break; |
|
447 | - case 21: |
|
448 | - $tokens[$len-2][] = $tokens[$len]; |
|
449 | - $yyval->token = $tokens[$len-2]; |
|
450 | - break; |
|
350 | + case 1: |
|
351 | + $yytext = preg_replace_callback('{(?:\\\\["bfnrt/\\\\]|\\\\u[a-fA-F0-9]{4})}', array($this, 'stringInterpolation'), $yytext); |
|
352 | + $yyval->token = $yytext; |
|
353 | + break; |
|
354 | + case 2: |
|
355 | + if (strpos($yytext, 'e') !== false || strpos($yytext, 'E') !== false) { |
|
356 | + $yyval->token = \floatval($yytext); |
|
357 | + } else { |
|
358 | + $yyval->token = strpos($yytext, '.') === false ? \intval($yytext) : \floatval($yytext); |
|
359 | + } |
|
360 | + break; |
|
361 | + case 3: |
|
362 | + $yyval->token = null; |
|
363 | + break; |
|
364 | + case 4: |
|
365 | + $yyval->token = true; |
|
366 | + break; |
|
367 | + case 5: |
|
368 | + $yyval->token = false; |
|
369 | + break; |
|
370 | + case 6: |
|
371 | + return $yyval->token = $tokens[$len-1]; |
|
372 | + case 13: |
|
373 | + if ($this->flags & self::PARSE_TO_ASSOC) { |
|
374 | + $yyval->token = array(); |
|
375 | + } else { |
|
376 | + $yyval->token = new stdClass; |
|
377 | + } |
|
378 | + break; |
|
379 | + case 14: |
|
380 | + $yyval->token = $tokens[$len-1]; |
|
381 | + break; |
|
382 | + case 15: |
|
383 | + $yyval->token = array($tokens[$len-2], $tokens[$len]); |
|
384 | + break; |
|
385 | + case 16: |
|
386 | + if (PHP_VERSION_ID < 70100) { |
|
387 | + $property = $tokens[$len][0] === '' ? '_empty_' : $tokens[$len][0]; |
|
388 | + } else { |
|
389 | + $property = $tokens[$len][0]; |
|
390 | + } |
|
391 | + if ($this->flags & self::PARSE_TO_ASSOC) { |
|
392 | + $yyval->token = array(); |
|
393 | + $yyval->token[$property] = $tokens[$len][1]; |
|
394 | + } else { |
|
395 | + $yyval->token = new stdClass; |
|
396 | + $yyval->token->$property = $tokens[$len][1]; |
|
397 | + } |
|
398 | + break; |
|
399 | + case 17: |
|
400 | + if ($this->flags & self::PARSE_TO_ASSOC) { |
|
401 | + $yyval->token =& $tokens[$len-2]; |
|
402 | + $key = $tokens[$len][0]; |
|
403 | + if (($this->flags & self::DETECT_KEY_CONFLICTS) && isset($tokens[$len-2][$key])) { |
|
404 | + $errStr = 'Parse error on line ' . ($yylineno+1) . ":\n"; |
|
405 | + $errStr .= $this->lexer->showPosition() . "\n"; |
|
406 | + $errStr .= "Duplicate key: ".$tokens[$len][0]; |
|
407 | + throw new DuplicateKeyException($errStr, $tokens[$len][0], array('line' => $yylineno+1)); |
|
408 | + } elseif (($this->flags & self::ALLOW_DUPLICATE_KEYS) && isset($tokens[$len-2][$key])) { |
|
409 | + $duplicateCount = 1; |
|
410 | + do { |
|
411 | + $duplicateKey = $key . '.' . $duplicateCount++; |
|
412 | + } while (isset($tokens[$len-2][$duplicateKey])); |
|
413 | + $key = $duplicateKey; |
|
414 | + } |
|
415 | + $tokens[$len-2][$key] = $tokens[$len][1]; |
|
416 | + } else { |
|
417 | + $yyval->token = $tokens[$len-2]; |
|
418 | + if (PHP_VERSION_ID < 70100) { |
|
419 | + $key = $tokens[$len][0] === '' ? '_empty_' : $tokens[$len][0]; |
|
420 | + } else { |
|
421 | + $key = $tokens[$len][0]; |
|
422 | + } |
|
423 | + if (($this->flags & self::DETECT_KEY_CONFLICTS) && isset($tokens[$len-2]->{$key})) { |
|
424 | + $errStr = 'Parse error on line ' . ($yylineno+1) . ":\n"; |
|
425 | + $errStr .= $this->lexer->showPosition() . "\n"; |
|
426 | + $errStr .= "Duplicate key: ".$tokens[$len][0]; |
|
427 | + throw new DuplicateKeyException($errStr, $tokens[$len][0], array('line' => $yylineno+1)); |
|
428 | + } elseif (($this->flags & self::ALLOW_DUPLICATE_KEYS) && isset($tokens[$len-2]->{$key})) { |
|
429 | + $duplicateCount = 1; |
|
430 | + do { |
|
431 | + $duplicateKey = $key . '.' . $duplicateCount++; |
|
432 | + } while (isset($tokens[$len-2]->$duplicateKey)); |
|
433 | + $key = $duplicateKey; |
|
434 | + } |
|
435 | + $tokens[$len-2]->$key = $tokens[$len][1]; |
|
436 | + } |
|
437 | + break; |
|
438 | + case 18: |
|
439 | + $yyval->token = array(); |
|
440 | + break; |
|
441 | + case 19: |
|
442 | + $yyval->token = $tokens[$len-1]; |
|
443 | + break; |
|
444 | + case 20: |
|
445 | + $yyval->token = array($tokens[$len]); |
|
446 | + break; |
|
447 | + case 21: |
|
448 | + $tokens[$len-2][] = $tokens[$len]; |
|
449 | + $yyval->token = $tokens[$len-2]; |
|
450 | + break; |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | return new Undefined(); |
@@ -456,24 +456,24 @@ discard block |
||
456 | 456 | private function stringInterpolation($match) |
457 | 457 | { |
458 | 458 | switch ($match[0]) { |
459 | - case '\\\\': |
|
460 | - return '\\'; |
|
461 | - case '\"': |
|
462 | - return '"'; |
|
463 | - case '\b': |
|
464 | - return \chr(8); |
|
465 | - case '\f': |
|
466 | - return \chr(12); |
|
467 | - case '\n': |
|
468 | - return "\n"; |
|
469 | - case '\r': |
|
470 | - return "\r"; |
|
471 | - case '\t': |
|
472 | - return "\t"; |
|
473 | - case '\/': |
|
474 | - return "/"; |
|
475 | - default: |
|
476 | - return html_entity_decode('&#x'.ltrim(substr($match[0], 2), '0').';', ENT_QUOTES, 'UTF-8'); |
|
459 | + case '\\\\': |
|
460 | + return '\\'; |
|
461 | + case '\"': |
|
462 | + return '"'; |
|
463 | + case '\b': |
|
464 | + return \chr(8); |
|
465 | + case '\f': |
|
466 | + return \chr(12); |
|
467 | + case '\n': |
|
468 | + return "\n"; |
|
469 | + case '\r': |
|
470 | + return "\r"; |
|
471 | + case '\t': |
|
472 | + return "\t"; |
|
473 | + case '\/': |
|
474 | + return "/"; |
|
475 | + default: |
|
476 | + return html_entity_decode('&#x'.ltrim(substr($match[0], 2), '0').';', ENT_QUOTES, 'UTF-8'); |
|
477 | 477 | } |
478 | 478 | } |
479 | 479 |
@@ -91,34 +91,34 @@ discard block |
||
91 | 91 | |
92 | 92 | private $productions_ = array( |
93 | 93 | 0, |
94 | - array(3, 1), |
|
95 | - array(5, 1), |
|
96 | - array(7, 1), |
|
97 | - array(9, 1), |
|
98 | - array(9, 1), |
|
99 | - array(12, 2), |
|
100 | - array(13, 1), |
|
101 | - array(13, 1), |
|
102 | - array(13, 1), |
|
103 | - array(13, 1), |
|
104 | - array(13, 1), |
|
105 | - array(13, 1), |
|
106 | - array(15, 2), |
|
107 | - array(15, 3), |
|
108 | - array(20, 3), |
|
109 | - array(19, 1), |
|
110 | - array(19, 3), |
|
111 | - array(16, 2), |
|
112 | - array(16, 3), |
|
113 | - array(25, 1), |
|
114 | - array(25, 3) |
|
94 | + array( 3, 1 ), |
|
95 | + array( 5, 1 ), |
|
96 | + array( 7, 1 ), |
|
97 | + array( 9, 1 ), |
|
98 | + array( 9, 1 ), |
|
99 | + array( 12, 2 ), |
|
100 | + array( 13, 1 ), |
|
101 | + array( 13, 1 ), |
|
102 | + array( 13, 1 ), |
|
103 | + array( 13, 1 ), |
|
104 | + array( 13, 1 ), |
|
105 | + array( 13, 1 ), |
|
106 | + array( 15, 2 ), |
|
107 | + array( 15, 3 ), |
|
108 | + array( 20, 3 ), |
|
109 | + array( 19, 1 ), |
|
110 | + array( 19, 3 ), |
|
111 | + array( 16, 2 ), |
|
112 | + array( 16, 3 ), |
|
113 | + array( 25, 1 ), |
|
114 | + array( 25, 3 ) |
|
115 | 115 | ); |
116 | 116 | |
117 | - private $table = array(array(3 => 5, 4 => array(1,12), 5 => 6, 6 => array(1,13), 7 => 3, 8 => array(1,9), 9 => 4, 10 => array(1,10), 11 => array(1,11), 12 => 1, 13 => 2, 15 => 7, 16 => 8, 17 => array(1,14), 23 => array(1,15)), array( 1 => array(3)), array( 14 => array(1,16)), array( 14 => array(2,7), 18 => array(2,7), 22 => array(2,7), 24 => array(2,7)), array( 14 => array(2,8), 18 => array(2,8), 22 => array(2,8), 24 => array(2,8)), array( 14 => array(2,9), 18 => array(2,9), 22 => array(2,9), 24 => array(2,9)), array( 14 => array(2,10), 18 => array(2,10), 22 => array(2,10), 24 => array(2,10)), array( 14 => array(2,11), 18 => array(2,11), 22 => array(2,11), 24 => array(2,11)), array( 14 => array(2,12), 18 => array(2,12), 22 => array(2,12), 24 => array(2,12)), array( 14 => array(2,3), 18 => array(2,3), 22 => array(2,3), 24 => array(2,3)), array( 14 => array(2,4), 18 => array(2,4), 22 => array(2,4), 24 => array(2,4)), array( 14 => array(2,5), 18 => array(2,5), 22 => array(2,5), 24 => array(2,5)), array( 14 => array(2,1), 18 => array(2,1), 21 => array(2,1), 22 => array(2,1), 24 => array(2,1)), array( 14 => array(2,2), 18 => array(2,2), 22 => array(2,2), 24 => array(2,2)), array( 3 => 20, 4 => array(1,12), 18 => array(1,17), 19 => 18, 20 => 19 ), array( 3 => 5, 4 => array(1,12), 5 => 6, 6 => array(1,13), 7 => 3, 8 => array(1,9), 9 => 4, 10 => array(1,10), 11 => array(1,11), 13 => 23, 15 => 7, 16 => 8, 17 => array(1,14), 23 => array(1,15), 24 => array(1,21), 25 => 22 ), array( 1 => array(2,6)), array( 14 => array(2,13), 18 => array(2,13), 22 => array(2,13), 24 => array(2,13)), array( 18 => array(1,24), 22 => array(1,25)), array( 18 => array(2,16), 22 => array(2,16)), array( 21 => array(1,26)), array( 14 => array(2,18), 18 => array(2,18), 22 => array(2,18), 24 => array(2,18)), array( 22 => array(1,28), 24 => array(1,27)), array( 22 => array(2,20), 24 => array(2,20)), array( 14 => array(2,14), 18 => array(2,14), 22 => array(2,14), 24 => array(2,14)), array( 3 => 20, 4 => array(1,12), 20 => 29 ), array( 3 => 5, 4 => array(1,12), 5 => 6, 6 => array(1,13), 7 => 3, 8 => array(1,9), 9 => 4, 10 => array(1,10), 11 => array(1,11), 13 => 30, 15 => 7, 16 => 8, 17 => array(1,14), 23 => array(1,15)), array( 14 => array(2,19), 18 => array(2,19), 22 => array(2,19), 24 => array(2,19)), array( 3 => 5, 4 => array(1,12), 5 => 6, 6 => array(1,13), 7 => 3, 8 => array(1,9), 9 => 4, 10 => array(1,10), 11 => array(1,11), 13 => 31, 15 => 7, 16 => 8, 17 => array(1,14), 23 => array(1,15)), array( 18 => array(2,17), 22 => array(2,17)), array( 18 => array(2,15), 22 => array(2,15)), array( 22 => array(2,21), 24 => array(2,21)), |
|
117 | + private $table = array( array( 3 => 5, 4 => array( 1, 12 ), 5 => 6, 6 => array( 1, 13 ), 7 => 3, 8 => array( 1, 9 ), 9 => 4, 10 => array( 1, 10 ), 11 => array( 1, 11 ), 12 => 1, 13 => 2, 15 => 7, 16 => 8, 17 => array( 1, 14 ), 23 => array( 1, 15 ) ), array( 1 => array( 3 ) ), array( 14 => array( 1, 16 ) ), array( 14 => array( 2, 7 ), 18 => array( 2, 7 ), 22 => array( 2, 7 ), 24 => array( 2, 7 ) ), array( 14 => array( 2, 8 ), 18 => array( 2, 8 ), 22 => array( 2, 8 ), 24 => array( 2, 8 ) ), array( 14 => array( 2, 9 ), 18 => array( 2, 9 ), 22 => array( 2, 9 ), 24 => array( 2, 9 ) ), array( 14 => array( 2, 10 ), 18 => array( 2, 10 ), 22 => array( 2, 10 ), 24 => array( 2, 10 ) ), array( 14 => array( 2, 11 ), 18 => array( 2, 11 ), 22 => array( 2, 11 ), 24 => array( 2, 11 ) ), array( 14 => array( 2, 12 ), 18 => array( 2, 12 ), 22 => array( 2, 12 ), 24 => array( 2, 12 ) ), array( 14 => array( 2, 3 ), 18 => array( 2, 3 ), 22 => array( 2, 3 ), 24 => array( 2, 3 ) ), array( 14 => array( 2, 4 ), 18 => array( 2, 4 ), 22 => array( 2, 4 ), 24 => array( 2, 4 ) ), array( 14 => array( 2, 5 ), 18 => array( 2, 5 ), 22 => array( 2, 5 ), 24 => array( 2, 5 ) ), array( 14 => array( 2, 1 ), 18 => array( 2, 1 ), 21 => array( 2, 1 ), 22 => array( 2, 1 ), 24 => array( 2, 1 ) ), array( 14 => array( 2, 2 ), 18 => array( 2, 2 ), 22 => array( 2, 2 ), 24 => array( 2, 2 ) ), array( 3 => 20, 4 => array( 1, 12 ), 18 => array( 1, 17 ), 19 => 18, 20 => 19 ), array( 3 => 5, 4 => array( 1, 12 ), 5 => 6, 6 => array( 1, 13 ), 7 => 3, 8 => array( 1, 9 ), 9 => 4, 10 => array( 1, 10 ), 11 => array( 1, 11 ), 13 => 23, 15 => 7, 16 => 8, 17 => array( 1, 14 ), 23 => array( 1, 15 ), 24 => array( 1, 21 ), 25 => 22 ), array( 1 => array( 2, 6 ) ), array( 14 => array( 2, 13 ), 18 => array( 2, 13 ), 22 => array( 2, 13 ), 24 => array( 2, 13 ) ), array( 18 => array( 1, 24 ), 22 => array( 1, 25 ) ), array( 18 => array( 2, 16 ), 22 => array( 2, 16 ) ), array( 21 => array( 1, 26 ) ), array( 14 => array( 2, 18 ), 18 => array( 2, 18 ), 22 => array( 2, 18 ), 24 => array( 2, 18 ) ), array( 22 => array( 1, 28 ), 24 => array( 1, 27 ) ), array( 22 => array( 2, 20 ), 24 => array( 2, 20 ) ), array( 14 => array( 2, 14 ), 18 => array( 2, 14 ), 22 => array( 2, 14 ), 24 => array( 2, 14 ) ), array( 3 => 20, 4 => array( 1, 12 ), 20 => 29 ), array( 3 => 5, 4 => array( 1, 12 ), 5 => 6, 6 => array( 1, 13 ), 7 => 3, 8 => array( 1, 9 ), 9 => 4, 10 => array( 1, 10 ), 11 => array( 1, 11 ), 13 => 30, 15 => 7, 16 => 8, 17 => array( 1, 14 ), 23 => array( 1, 15 ) ), array( 14 => array( 2, 19 ), 18 => array( 2, 19 ), 22 => array( 2, 19 ), 24 => array( 2, 19 ) ), array( 3 => 5, 4 => array( 1, 12 ), 5 => 6, 6 => array( 1, 13 ), 7 => 3, 8 => array( 1, 9 ), 9 => 4, 10 => array( 1, 10 ), 11 => array( 1, 11 ), 13 => 31, 15 => 7, 16 => 8, 17 => array( 1, 14 ), 23 => array( 1, 15 ) ), array( 18 => array( 2, 17 ), 22 => array( 2, 17 ) ), array( 18 => array( 2, 15 ), 22 => array( 2, 15 ) ), array( 22 => array( 2, 21 ), 24 => array( 2, 21 ) ), |
|
118 | 118 | ); |
119 | 119 | |
120 | 120 | private $defaultActions = array( |
121 | - 16 => array(2, 6) |
|
121 | + 16 => array( 2, 6 ) |
|
122 | 122 | ); |
123 | 123 | |
124 | 124 | /** |
@@ -126,11 +126,11 @@ discard block |
||
126 | 126 | * @param int $flags Bitmask of parse/lint options (see constants of this class) |
127 | 127 | * @return null|ParsingException null if no error is found, a ParsingException containing all details otherwise |
128 | 128 | */ |
129 | - public function lint($input, $flags = 0) |
|
129 | + public function lint( $input, $flags = 0 ) |
|
130 | 130 | { |
131 | 131 | try { |
132 | - $this->parse($input, $flags); |
|
133 | - } catch (ParsingException $e) { |
|
132 | + $this->parse( $input, $flags ); |
|
133 | + } catch ( ParsingException $e ) { |
|
134 | 134 | return $e; |
135 | 135 | } |
136 | 136 | return null; |
@@ -142,14 +142,14 @@ discard block |
||
142 | 142 | * @return mixed |
143 | 143 | * @throws ParsingException |
144 | 144 | */ |
145 | - public function parse($input, $flags = 0) |
|
145 | + public function parse( $input, $flags = 0 ) |
|
146 | 146 | { |
147 | - $this->failOnBOM($input); |
|
147 | + $this->failOnBOM( $input ); |
|
148 | 148 | |
149 | 149 | $this->flags = $flags; |
150 | 150 | |
151 | - $this->stack = array(0); |
|
152 | - $this->vstack = array(null); |
|
151 | + $this->stack = array( 0 ); |
|
152 | + $this->vstack = array( null ); |
|
153 | 153 | $this->lstack = array(); |
154 | 154 | |
155 | 155 | $yytext = ''; |
@@ -160,10 +160,10 @@ discard block |
||
160 | 160 | $EOF = 1; |
161 | 161 | |
162 | 162 | $this->lexer = new Lexer(); |
163 | - $this->lexer->setInput($input); |
|
163 | + $this->lexer->setInput( $input ); |
|
164 | 164 | |
165 | 165 | $yyloc = $this->lexer->yylloc; |
166 | - $this->lstack[] = $yyloc; |
|
166 | + $this->lstack[ ] = $yyloc; |
|
167 | 167 | |
168 | 168 | $symbol = null; |
169 | 169 | $preErrorSymbol = null; |
@@ -178,70 +178,70 @@ discard block |
||
178 | 178 | $expected = null; |
179 | 179 | $errStr = null; |
180 | 180 | |
181 | - while (true) { |
|
181 | + while ( true ) { |
|
182 | 182 | // retrieve state number from top of stack |
183 | - $state = $this->stack[\count($this->stack)-1]; |
|
183 | + $state = $this->stack[ \count( $this->stack ) - 1 ]; |
|
184 | 184 | |
185 | 185 | // use default actions if available |
186 | - if (isset($this->defaultActions[$state])) { |
|
187 | - $action = $this->defaultActions[$state]; |
|
186 | + if ( isset( $this->defaultActions[ $state ] ) ) { |
|
187 | + $action = $this->defaultActions[ $state ]; |
|
188 | 188 | } else { |
189 | - if ($symbol == null) { |
|
189 | + if ( $symbol == null ) { |
|
190 | 190 | $symbol = $this->lex(); |
191 | 191 | } |
192 | 192 | // read action for current state and first input |
193 | - $action = isset($this->table[$state][$symbol]) ? $this->table[$state][$symbol] : false; |
|
193 | + $action = isset( $this->table[ $state ][ $symbol ] ) ? $this->table[ $state ][ $symbol ] : false; |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | // handle parse error |
197 | - if (!$action || !$action[0]) { |
|
198 | - if (!$recovering) { |
|
197 | + if ( ! $action || ! $action[ 0 ] ) { |
|
198 | + if ( ! $recovering ) { |
|
199 | 199 | // Report error |
200 | 200 | $expected = array(); |
201 | - foreach ($this->table[$state] as $p => $ignore) { |
|
202 | - if (isset($this->terminals_[$p]) && $p > 2) { |
|
203 | - $expected[] = "'" . $this->terminals_[$p] . "'"; |
|
201 | + foreach ( $this->table[ $state ] as $p => $ignore ) { |
|
202 | + if ( isset( $this->terminals_[ $p ] ) && $p > 2 ) { |
|
203 | + $expected[ ] = "'" . $this->terminals_[ $p ] . "'"; |
|
204 | 204 | } |
205 | 205 | } |
206 | 206 | |
207 | 207 | $message = null; |
208 | - if (\in_array("'STRING'", $expected) && \in_array(substr($this->lexer->match, 0, 1), array('"', "'"))) { |
|
208 | + if ( \in_array( "'STRING'", $expected ) && \in_array( substr( $this->lexer->match, 0, 1 ), array( '"', "'" ) ) ) { |
|
209 | 209 | $message = "Invalid string"; |
210 | - if ("'" === substr($this->lexer->match, 0, 1)) { |
|
210 | + if ( "'" === substr( $this->lexer->match, 0, 1 ) ) { |
|
211 | 211 | $message .= ", it appears you used single quotes instead of double quotes"; |
212 | - } elseif (preg_match('{".+?(\\\\[^"bfnrt/\\\\u](...)?)}', $this->lexer->getFullUpcomingInput(), $match)) { |
|
213 | - $message .= ", it appears you have an unescaped backslash at: ".$match[1]; |
|
214 | - } elseif (preg_match('{"(?:[^"]+|\\\\")*$}m', $this->lexer->getFullUpcomingInput())) { |
|
212 | + } elseif ( preg_match( '{".+?(\\\\[^"bfnrt/\\\\u](...)?)}', $this->lexer->getFullUpcomingInput(), $match ) ) { |
|
213 | + $message .= ", it appears you have an unescaped backslash at: " . $match[ 1 ]; |
|
214 | + } elseif ( preg_match( '{"(?:[^"]+|\\\\")*$}m', $this->lexer->getFullUpcomingInput() ) ) { |
|
215 | 215 | $message .= ", it appears you forgot to terminate a string, or attempted to write a multiline string which is invalid"; |
216 | 216 | } |
217 | 217 | } |
218 | 218 | |
219 | - $errStr = 'Parse error on line ' . ($yylineno+1) . ":\n"; |
|
219 | + $errStr = 'Parse error on line ' . ( $yylineno + 1 ) . ":\n"; |
|
220 | 220 | $errStr .= $this->lexer->showPosition() . "\n"; |
221 | - if ($message) { |
|
221 | + if ( $message ) { |
|
222 | 222 | $errStr .= $message; |
223 | 223 | } else { |
224 | - $errStr .= (\count($expected) > 1) ? "Expected one of: " : "Expected: "; |
|
225 | - $errStr .= implode(', ', $expected); |
|
224 | + $errStr .= ( \count( $expected ) > 1 ) ? "Expected one of: " : "Expected: "; |
|
225 | + $errStr .= implode( ', ', $expected ); |
|
226 | 226 | } |
227 | 227 | |
228 | - if (',' === substr(trim($this->lexer->getPastInput()), -1)) { |
|
228 | + if ( ',' === substr( trim( $this->lexer->getPastInput() ), -1 ) ) { |
|
229 | 229 | $errStr .= " - It appears you have an extra trailing comma"; |
230 | 230 | } |
231 | 231 | |
232 | - $this->parseError($errStr, array( |
|
232 | + $this->parseError( $errStr, array( |
|
233 | 233 | 'text' => $this->lexer->match, |
234 | - 'token' => !empty($this->terminals_[$symbol]) ? $this->terminals_[$symbol] : $symbol, |
|
234 | + 'token' => ! empty( $this->terminals_[ $symbol ] ) ? $this->terminals_[ $symbol ] : $symbol, |
|
235 | 235 | 'line' => $this->lexer->yylineno, |
236 | 236 | 'loc' => $yyloc, |
237 | 237 | 'expected' => $expected, |
238 | - )); |
|
238 | + ) ); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | // just recovered from another error |
242 | - if ($recovering == 3) { |
|
243 | - if ($symbol == $EOF) { |
|
244 | - throw new ParsingException($errStr ?: 'Parsing halted.'); |
|
242 | + if ( $recovering == 3 ) { |
|
243 | + if ( $symbol == $EOF ) { |
|
244 | + throw new ParsingException( $errStr ?: 'Parsing halted.' ); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | // discard current lookahead and grab another |
@@ -253,43 +253,43 @@ discard block |
||
253 | 253 | } |
254 | 254 | |
255 | 255 | // try to recover from error |
256 | - while (true) { |
|
256 | + while ( true ) { |
|
257 | 257 | // check for error recovery rule in this state |
258 | - if (\array_key_exists($TERROR, $this->table[$state])) { |
|
258 | + if ( \array_key_exists( $TERROR, $this->table[ $state ] ) ) { |
|
259 | 259 | break; |
260 | 260 | } |
261 | - if ($state == 0) { |
|
262 | - throw new ParsingException($errStr ?: 'Parsing halted.'); |
|
261 | + if ( $state == 0 ) { |
|
262 | + throw new ParsingException( $errStr ?: 'Parsing halted.' ); |
|
263 | 263 | } |
264 | - $this->popStack(1); |
|
265 | - $state = $this->stack[\count($this->stack)-1]; |
|
264 | + $this->popStack( 1 ); |
|
265 | + $state = $this->stack[ \count( $this->stack ) - 1 ]; |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | $preErrorSymbol = $symbol; // save the lookahead token |
269 | - $symbol = $TERROR; // insert generic error symbol as new lookahead |
|
270 | - $state = $this->stack[\count($this->stack)-1]; |
|
271 | - $action = isset($this->table[$state][$TERROR]) ? $this->table[$state][$TERROR] : false; |
|
269 | + $symbol = $TERROR; // insert generic error symbol as new lookahead |
|
270 | + $state = $this->stack[ \count( $this->stack ) - 1 ]; |
|
271 | + $action = isset( $this->table[ $state ][ $TERROR ] ) ? $this->table[ $state ][ $TERROR ] : false; |
|
272 | 272 | $recovering = 3; // allow 3 real symbols to be shifted before reporting a new error |
273 | 273 | } |
274 | 274 | |
275 | 275 | // this shouldn't happen, unless resolve defaults are off |
276 | - if (\is_array($action[0]) && \count($action) > 1) { |
|
277 | - throw new ParsingException('Parse Error: multiple actions possible at state: ' . $state . ', token: ' . $symbol); |
|
276 | + if ( \is_array( $action[ 0 ] ) && \count( $action ) > 1 ) { |
|
277 | + throw new ParsingException( 'Parse Error: multiple actions possible at state: ' . $state . ', token: ' . $symbol ); |
|
278 | 278 | } |
279 | 279 | |
280 | - switch ($action[0]) { |
|
280 | + switch ( $action[ 0 ] ) { |
|
281 | 281 | case 1: // shift |
282 | - $this->stack[] = $symbol; |
|
283 | - $this->vstack[] = $this->lexer->yytext; |
|
284 | - $this->lstack[] = $this->lexer->yylloc; |
|
285 | - $this->stack[] = $action[1]; // push state |
|
282 | + $this->stack[ ] = $symbol; |
|
283 | + $this->vstack[ ] = $this->lexer->yytext; |
|
284 | + $this->lstack[ ] = $this->lexer->yylloc; |
|
285 | + $this->stack[ ] = $action[ 1 ]; // push state |
|
286 | 286 | $symbol = null; |
287 | - if (!$preErrorSymbol) { // normal execution/no error |
|
287 | + if ( ! $preErrorSymbol ) { // normal execution/no error |
|
288 | 288 | $yyleng = $this->lexer->yyleng; |
289 | 289 | $yytext = $this->lexer->yytext; |
290 | 290 | $yylineno = $this->lexer->yylineno; |
291 | 291 | $yyloc = $this->lexer->yylloc; |
292 | - if ($recovering > 0) { |
|
292 | + if ( $recovering > 0 ) { |
|
293 | 293 | $recovering--; |
294 | 294 | } |
295 | 295 | } else { // error just occurred, resume old lookahead f/ before error |
@@ -299,32 +299,32 @@ discard block |
||
299 | 299 | break; |
300 | 300 | |
301 | 301 | case 2: // reduce |
302 | - $len = $this->productions_[$action[1]][1]; |
|
302 | + $len = $this->productions_[ $action[ 1 ] ][ 1 ]; |
|
303 | 303 | |
304 | 304 | // perform semantic action |
305 | - $yyval->token = $this->vstack[\count($this->vstack) - $len]; // default to $$ = $1 |
|
305 | + $yyval->token = $this->vstack[ \count( $this->vstack ) - $len ]; // default to $$ = $1 |
|
306 | 306 | // default location, uses first token for firsts, last for lasts |
307 | 307 | $yyval->store = array( // _$ = store |
308 | - 'first_line' => $this->lstack[\count($this->lstack) - ($len ?: 1)]['first_line'], |
|
309 | - 'last_line' => $this->lstack[\count($this->lstack) - 1]['last_line'], |
|
310 | - 'first_column' => $this->lstack[\count($this->lstack) - ($len ?: 1)]['first_column'], |
|
311 | - 'last_column' => $this->lstack[\count($this->lstack) - 1]['last_column'], |
|
308 | + 'first_line' => $this->lstack[ \count( $this->lstack ) - ( $len ?: 1 ) ][ 'first_line' ], |
|
309 | + 'last_line' => $this->lstack[ \count( $this->lstack ) - 1 ][ 'last_line' ], |
|
310 | + 'first_column' => $this->lstack[ \count( $this->lstack ) - ( $len ?: 1 ) ][ 'first_column' ], |
|
311 | + 'last_column' => $this->lstack[ \count( $this->lstack ) - 1 ][ 'last_column' ], |
|
312 | 312 | ); |
313 | - $r = $this->performAction($yyval, $yytext, $yyleng, $yylineno, $action[1], $this->vstack); |
|
313 | + $r = $this->performAction( $yyval, $yytext, $yyleng, $yylineno, $action[ 1 ], $this->vstack ); |
|
314 | 314 | |
315 | - if (!$r instanceof Undefined) { |
|
315 | + if ( ! $r instanceof Undefined ) { |
|
316 | 316 | return $r; |
317 | 317 | } |
318 | 318 | |
319 | - if ($len) { |
|
320 | - $this->popStack($len); |
|
319 | + if ( $len ) { |
|
320 | + $this->popStack( $len ); |
|
321 | 321 | } |
322 | 322 | |
323 | - $this->stack[] = $this->productions_[$action[1]][0]; // push nonterminal (reduce) |
|
324 | - $this->vstack[] = $yyval->token; |
|
325 | - $this->lstack[] = $yyval->store; |
|
326 | - $newState = $this->table[$this->stack[\count($this->stack)-2]][$this->stack[\count($this->stack)-1]]; |
|
327 | - $this->stack[] = $newState; |
|
323 | + $this->stack[ ] = $this->productions_[ $action[ 1 ] ][ 0 ]; // push nonterminal (reduce) |
|
324 | + $this->vstack[ ] = $yyval->token; |
|
325 | + $this->lstack[ ] = $yyval->store; |
|
326 | + $newState = $this->table[ $this->stack[ \count( $this->stack ) - 2 ] ][ $this->stack[ \count( $this->stack ) - 1 ] ]; |
|
327 | + $this->stack[ ] = $newState; |
|
328 | 328 | break; |
329 | 329 | |
330 | 330 | case 3: // accept |
@@ -334,28 +334,28 @@ discard block |
||
334 | 334 | } |
335 | 335 | } |
336 | 336 | |
337 | - protected function parseError($str, $hash) |
|
337 | + protected function parseError( $str, $hash ) |
|
338 | 338 | { |
339 | - throw new ParsingException($str, $hash); |
|
339 | + throw new ParsingException( $str, $hash ); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | // $$ = $tokens // needs to be passed by ref? |
343 | 343 | // $ = $token |
344 | 344 | // _$ removed, useless? |
345 | - private function performAction(stdClass $yyval, $yytext, $yyleng, $yylineno, $yystate, &$tokens) |
|
345 | + private function performAction( stdClass $yyval, $yytext, $yyleng, $yylineno, $yystate, &$tokens ) |
|
346 | 346 | { |
347 | 347 | // $0 = $len |
348 | - $len = \count($tokens) - 1; |
|
349 | - switch ($yystate) { |
|
348 | + $len = \count( $tokens ) - 1; |
|
349 | + switch ( $yystate ) { |
|
350 | 350 | case 1: |
351 | - $yytext = preg_replace_callback('{(?:\\\\["bfnrt/\\\\]|\\\\u[a-fA-F0-9]{4})}', array($this, 'stringInterpolation'), $yytext); |
|
351 | + $yytext = preg_replace_callback( '{(?:\\\\["bfnrt/\\\\]|\\\\u[a-fA-F0-9]{4})}', array( $this, 'stringInterpolation' ), $yytext ); |
|
352 | 352 | $yyval->token = $yytext; |
353 | 353 | break; |
354 | 354 | case 2: |
355 | - if (strpos($yytext, 'e') !== false || strpos($yytext, 'E') !== false) { |
|
356 | - $yyval->token = \floatval($yytext); |
|
355 | + if ( strpos( $yytext, 'e' ) !== false || strpos( $yytext, 'E' ) !== false ) { |
|
356 | + $yyval->token = \floatval( $yytext ); |
|
357 | 357 | } else { |
358 | - $yyval->token = strpos($yytext, '.') === false ? \intval($yytext) : \floatval($yytext); |
|
358 | + $yyval->token = strpos( $yytext, '.' ) === false ? \intval( $yytext ) : \floatval( $yytext ); |
|
359 | 359 | } |
360 | 360 | break; |
361 | 361 | case 3: |
@@ -368,102 +368,102 @@ discard block |
||
368 | 368 | $yyval->token = false; |
369 | 369 | break; |
370 | 370 | case 6: |
371 | - return $yyval->token = $tokens[$len-1]; |
|
371 | + return $yyval->token = $tokens[ $len - 1 ]; |
|
372 | 372 | case 13: |
373 | - if ($this->flags & self::PARSE_TO_ASSOC) { |
|
373 | + if ( $this->flags & self::PARSE_TO_ASSOC ) { |
|
374 | 374 | $yyval->token = array(); |
375 | 375 | } else { |
376 | 376 | $yyval->token = new stdClass; |
377 | 377 | } |
378 | 378 | break; |
379 | 379 | case 14: |
380 | - $yyval->token = $tokens[$len-1]; |
|
380 | + $yyval->token = $tokens[ $len - 1 ]; |
|
381 | 381 | break; |
382 | 382 | case 15: |
383 | - $yyval->token = array($tokens[$len-2], $tokens[$len]); |
|
383 | + $yyval->token = array( $tokens[ $len - 2 ], $tokens[ $len ] ); |
|
384 | 384 | break; |
385 | 385 | case 16: |
386 | - if (PHP_VERSION_ID < 70100) { |
|
387 | - $property = $tokens[$len][0] === '' ? '_empty_' : $tokens[$len][0]; |
|
386 | + if ( PHP_VERSION_ID < 70100 ) { |
|
387 | + $property = $tokens[ $len ][ 0 ] === '' ? '_empty_' : $tokens[ $len ][ 0 ]; |
|
388 | 388 | } else { |
389 | - $property = $tokens[$len][0]; |
|
389 | + $property = $tokens[ $len ][ 0 ]; |
|
390 | 390 | } |
391 | - if ($this->flags & self::PARSE_TO_ASSOC) { |
|
391 | + if ( $this->flags & self::PARSE_TO_ASSOC ) { |
|
392 | 392 | $yyval->token = array(); |
393 | - $yyval->token[$property] = $tokens[$len][1]; |
|
393 | + $yyval->token[ $property ] = $tokens[ $len ][ 1 ]; |
|
394 | 394 | } else { |
395 | 395 | $yyval->token = new stdClass; |
396 | - $yyval->token->$property = $tokens[$len][1]; |
|
396 | + $yyval->token->$property = $tokens[ $len ][ 1 ]; |
|
397 | 397 | } |
398 | 398 | break; |
399 | 399 | case 17: |
400 | - if ($this->flags & self::PARSE_TO_ASSOC) { |
|
401 | - $yyval->token =& $tokens[$len-2]; |
|
402 | - $key = $tokens[$len][0]; |
|
403 | - if (($this->flags & self::DETECT_KEY_CONFLICTS) && isset($tokens[$len-2][$key])) { |
|
404 | - $errStr = 'Parse error on line ' . ($yylineno+1) . ":\n"; |
|
400 | + if ( $this->flags & self::PARSE_TO_ASSOC ) { |
|
401 | + $yyval->token = & $tokens[ $len - 2 ]; |
|
402 | + $key = $tokens[ $len ][ 0 ]; |
|
403 | + if ( ( $this->flags & self::DETECT_KEY_CONFLICTS ) && isset( $tokens[ $len - 2 ][ $key ] ) ) { |
|
404 | + $errStr = 'Parse error on line ' . ( $yylineno + 1 ) . ":\n"; |
|
405 | 405 | $errStr .= $this->lexer->showPosition() . "\n"; |
406 | - $errStr .= "Duplicate key: ".$tokens[$len][0]; |
|
407 | - throw new DuplicateKeyException($errStr, $tokens[$len][0], array('line' => $yylineno+1)); |
|
408 | - } elseif (($this->flags & self::ALLOW_DUPLICATE_KEYS) && isset($tokens[$len-2][$key])) { |
|
406 | + $errStr .= "Duplicate key: " . $tokens[ $len ][ 0 ]; |
|
407 | + throw new DuplicateKeyException( $errStr, $tokens[ $len ][ 0 ], array( 'line' => $yylineno + 1 ) ); |
|
408 | + } elseif ( ( $this->flags & self::ALLOW_DUPLICATE_KEYS ) && isset( $tokens[ $len - 2 ][ $key ] ) ) { |
|
409 | 409 | $duplicateCount = 1; |
410 | 410 | do { |
411 | 411 | $duplicateKey = $key . '.' . $duplicateCount++; |
412 | - } while (isset($tokens[$len-2][$duplicateKey])); |
|
412 | + } while ( isset( $tokens[ $len - 2 ][ $duplicateKey ] ) ); |
|
413 | 413 | $key = $duplicateKey; |
414 | 414 | } |
415 | - $tokens[$len-2][$key] = $tokens[$len][1]; |
|
415 | + $tokens[ $len - 2 ][ $key ] = $tokens[ $len ][ 1 ]; |
|
416 | 416 | } else { |
417 | - $yyval->token = $tokens[$len-2]; |
|
418 | - if (PHP_VERSION_ID < 70100) { |
|
419 | - $key = $tokens[$len][0] === '' ? '_empty_' : $tokens[$len][0]; |
|
417 | + $yyval->token = $tokens[ $len - 2 ]; |
|
418 | + if ( PHP_VERSION_ID < 70100 ) { |
|
419 | + $key = $tokens[ $len ][ 0 ] === '' ? '_empty_' : $tokens[ $len ][ 0 ]; |
|
420 | 420 | } else { |
421 | - $key = $tokens[$len][0]; |
|
421 | + $key = $tokens[ $len ][ 0 ]; |
|
422 | 422 | } |
423 | - if (($this->flags & self::DETECT_KEY_CONFLICTS) && isset($tokens[$len-2]->{$key})) { |
|
424 | - $errStr = 'Parse error on line ' . ($yylineno+1) . ":\n"; |
|
423 | + if ( ( $this->flags & self::DETECT_KEY_CONFLICTS ) && isset( $tokens[ $len - 2 ]->{$key}) ) { |
|
424 | + $errStr = 'Parse error on line ' . ( $yylineno + 1 ) . ":\n"; |
|
425 | 425 | $errStr .= $this->lexer->showPosition() . "\n"; |
426 | - $errStr .= "Duplicate key: ".$tokens[$len][0]; |
|
427 | - throw new DuplicateKeyException($errStr, $tokens[$len][0], array('line' => $yylineno+1)); |
|
428 | - } elseif (($this->flags & self::ALLOW_DUPLICATE_KEYS) && isset($tokens[$len-2]->{$key})) { |
|
426 | + $errStr .= "Duplicate key: " . $tokens[ $len ][ 0 ]; |
|
427 | + throw new DuplicateKeyException( $errStr, $tokens[ $len ][ 0 ], array( 'line' => $yylineno + 1 ) ); |
|
428 | + } elseif ( ( $this->flags & self::ALLOW_DUPLICATE_KEYS ) && isset( $tokens[ $len - 2 ]->{$key}) ) { |
|
429 | 429 | $duplicateCount = 1; |
430 | 430 | do { |
431 | 431 | $duplicateKey = $key . '.' . $duplicateCount++; |
432 | - } while (isset($tokens[$len-2]->$duplicateKey)); |
|
432 | + } while ( isset( $tokens[ $len - 2 ]->$duplicateKey ) ); |
|
433 | 433 | $key = $duplicateKey; |
434 | 434 | } |
435 | - $tokens[$len-2]->$key = $tokens[$len][1]; |
|
435 | + $tokens[ $len - 2 ]->$key = $tokens[ $len ][ 1 ]; |
|
436 | 436 | } |
437 | 437 | break; |
438 | 438 | case 18: |
439 | 439 | $yyval->token = array(); |
440 | 440 | break; |
441 | 441 | case 19: |
442 | - $yyval->token = $tokens[$len-1]; |
|
442 | + $yyval->token = $tokens[ $len - 1 ]; |
|
443 | 443 | break; |
444 | 444 | case 20: |
445 | - $yyval->token = array($tokens[$len]); |
|
445 | + $yyval->token = array( $tokens[ $len ] ); |
|
446 | 446 | break; |
447 | 447 | case 21: |
448 | - $tokens[$len-2][] = $tokens[$len]; |
|
449 | - $yyval->token = $tokens[$len-2]; |
|
448 | + $tokens[ $len - 2 ][ ] = $tokens[ $len ]; |
|
449 | + $yyval->token = $tokens[ $len - 2 ]; |
|
450 | 450 | break; |
451 | 451 | } |
452 | 452 | |
453 | 453 | return new Undefined(); |
454 | 454 | } |
455 | 455 | |
456 | - private function stringInterpolation($match) |
|
456 | + private function stringInterpolation( $match ) |
|
457 | 457 | { |
458 | - switch ($match[0]) { |
|
458 | + switch ( $match[ 0 ] ) { |
|
459 | 459 | case '\\\\': |
460 | 460 | return '\\'; |
461 | 461 | case '\"': |
462 | 462 | return '"'; |
463 | 463 | case '\b': |
464 | - return \chr(8); |
|
464 | + return \chr( 8 ); |
|
465 | 465 | case '\f': |
466 | - return \chr(12); |
|
466 | + return \chr( 12 ); |
|
467 | 467 | case '\n': |
468 | 468 | return "\n"; |
469 | 469 | case '\r': |
@@ -473,35 +473,35 @@ discard block |
||
473 | 473 | case '\/': |
474 | 474 | return "/"; |
475 | 475 | default: |
476 | - return html_entity_decode('&#x'.ltrim(substr($match[0], 2), '0').';', ENT_QUOTES, 'UTF-8'); |
|
476 | + return html_entity_decode( '&#x' . ltrim( substr( $match[ 0 ], 2 ), '0' ) . ';', ENT_QUOTES, 'UTF-8' ); |
|
477 | 477 | } |
478 | 478 | } |
479 | 479 | |
480 | - private function popStack($n) |
|
480 | + private function popStack( $n ) |
|
481 | 481 | { |
482 | - $this->stack = \array_slice($this->stack, 0, - (2 * $n)); |
|
483 | - $this->vstack = \array_slice($this->vstack, 0, - $n); |
|
484 | - $this->lstack = \array_slice($this->lstack, 0, - $n); |
|
482 | + $this->stack = \array_slice( $this->stack, 0, - ( 2 * $n ) ); |
|
483 | + $this->vstack = \array_slice( $this->vstack, 0, - $n ); |
|
484 | + $this->lstack = \array_slice( $this->lstack, 0, - $n ); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | private function lex() |
488 | 488 | { |
489 | 489 | $token = $this->lexer->lex() ?: 1; // $end = 1 |
490 | 490 | // if token isn't its numeric value, convert |
491 | - if (!is_numeric($token)) { |
|
492 | - $token = isset($this->symbols[$token]) ? $this->symbols[$token] : $token; |
|
491 | + if ( ! is_numeric( $token ) ) { |
|
492 | + $token = isset( $this->symbols[ $token ] ) ? $this->symbols[ $token ] : $token; |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | return $token; |
496 | 496 | } |
497 | 497 | |
498 | - private function failOnBOM($input) |
|
498 | + private function failOnBOM( $input ) |
|
499 | 499 | { |
500 | 500 | // UTF-8 ByteOrderMark sequence |
501 | 501 | $bom = "\xEF\xBB\xBF"; |
502 | 502 | |
503 | - if (substr($input, 0, 3) === $bom) { |
|
504 | - $this->parseError("BOM detected, make sure your input does not include a Unicode Byte-Order-Mark", array()); |
|
503 | + if ( substr( $input, 0, 3 ) === $bom ) { |
|
504 | + $this->parseError( "BOM detected, make sure your input does not include a Unicode Byte-Order-Mark", array() ); |
|
505 | 505 | } |
506 | 506 | } |
507 | 507 | } |
@@ -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 |
@@ -13,27 +13,27 @@ |
||
13 | 13 | |
14 | 14 | class DuplicateKeyException extends ParsingException |
15 | 15 | { |
16 | - /** |
|
17 | - * @param string $message |
|
18 | - * @param string $key |
|
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 |
|
20 | - */ |
|
21 | - public function __construct($message, $key, array $details = array()) |
|
22 | - { |
|
23 | - $details['key'] = $key; |
|
24 | - parent::__construct($message, $details); |
|
25 | - } |
|
16 | + /** |
|
17 | + * @param string $message |
|
18 | + * @param string $key |
|
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 |
|
20 | + */ |
|
21 | + public function __construct($message, $key, array $details = array()) |
|
22 | + { |
|
23 | + $details['key'] = $key; |
|
24 | + parent::__construct($message, $details); |
|
25 | + } |
|
26 | 26 | |
27 | - public function getKey() |
|
28 | - { |
|
29 | - return $this->details['key']; |
|
30 | - } |
|
27 | + public function getKey() |
|
28 | + { |
|
29 | + return $this->details['key']; |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * @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 | - */ |
|
35 | - public function getDetails() |
|
36 | - { |
|
37 | - return $this->details; |
|
38 | - } |
|
32 | + /** |
|
33 | + * @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 | + */ |
|
35 | + public function getDetails() |
|
36 | + { |
|
37 | + return $this->details; |
|
38 | + } |
|
39 | 39 | } |
@@ -18,15 +18,15 @@ |
||
18 | 18 | * @param string $key |
19 | 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 |
20 | 20 | */ |
21 | - public function __construct($message, $key, array $details = array()) |
|
21 | + public function __construct( $message, $key, array $details = array() ) |
|
22 | 22 | { |
23 | - $details['key'] = $key; |
|
24 | - parent::__construct($message, $details); |
|
23 | + $details[ 'key' ] = $key; |
|
24 | + parent::__construct( $message, $details ); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | public function getKey() |
28 | 28 | { |
29 | - return $this->details['key']; |
|
29 | + return $this->details[ 'key' ]; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -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 | } |
@@ -18,216 +18,216 @@ |
||
18 | 18 | */ |
19 | 19 | class Lexer |
20 | 20 | { |
21 | - private $EOF = 1; |
|
22 | - /** |
|
23 | - * @phpstan-var array<int, string> |
|
24 | - */ |
|
25 | - private $rules = array( |
|
26 | - 0 => '/\G\s+/', |
|
27 | - 1 => '/\G-?([0-9]|[1-9][0-9]+)(\.[0-9]+)?([eE][+-]?[0-9]+)?\b/', |
|
28 | - 2 => '{\G"(?>\\\\["bfnrt/\\\\]|\\\\u[a-fA-F0-9]{4}|[^\0-\x1f\\\\"]++)*+"}', |
|
29 | - 3 => '/\G\{/', |
|
30 | - 4 => '/\G\}/', |
|
31 | - 5 => '/\G\[/', |
|
32 | - 6 => '/\G\]/', |
|
33 | - 7 => '/\G,/', |
|
34 | - 8 => '/\G:/', |
|
35 | - 9 => '/\Gtrue\b/', |
|
36 | - 10 => '/\Gfalse\b/', |
|
37 | - 11 => '/\Gnull\b/', |
|
38 | - 12 => '/\G$/', |
|
39 | - 13 => '/\G./', |
|
40 | - ); |
|
41 | - |
|
42 | - private $conditions = array( |
|
43 | - "INITIAL" => array( |
|
44 | - "rules" => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13), |
|
45 | - "inclusive" => true, |
|
46 | - ), |
|
47 | - ); |
|
48 | - |
|
49 | - private $conditionStack; |
|
50 | - private $input; |
|
51 | - private $more; |
|
52 | - private $done; |
|
53 | - private $offset; |
|
54 | - |
|
55 | - public $match; |
|
56 | - public $yylineno; |
|
57 | - public $yyleng; |
|
58 | - public $yytext; |
|
59 | - public $yylloc; |
|
60 | - |
|
61 | - public function lex() |
|
62 | - { |
|
63 | - $r = $this->next(); |
|
64 | - if (!$r instanceof Undefined) { |
|
65 | - return $r; |
|
66 | - } |
|
67 | - |
|
68 | - return $this->lex(); |
|
69 | - } |
|
70 | - |
|
71 | - public function setInput($input) |
|
72 | - { |
|
73 | - $this->input = $input; |
|
74 | - $this->more = false; |
|
75 | - $this->done = false; |
|
76 | - $this->offset = 0; |
|
77 | - $this->yylineno = $this->yyleng = 0; |
|
78 | - $this->yytext = $this->match = ''; |
|
79 | - $this->conditionStack = array('INITIAL'); |
|
80 | - $this->yylloc = array('first_line' => 1, 'first_column' => 0, 'last_line' => 1, 'last_column' => 0); |
|
81 | - |
|
82 | - return $this; |
|
83 | - } |
|
84 | - |
|
85 | - public function showPosition() |
|
86 | - { |
|
87 | - $pre = str_replace("\n", '', $this->getPastInput()); |
|
88 | - $c = str_repeat('-', max(0, \strlen($pre) - 1)); // new Array(pre.length + 1).join("-"); |
|
89 | - |
|
90 | - return $pre . str_replace("\n", '', $this->getUpcomingInput()) . "\n" . $c . "^"; |
|
91 | - } |
|
92 | - |
|
93 | - public function getPastInput() |
|
94 | - { |
|
95 | - $pastLength = $this->offset - \strlen($this->match); |
|
96 | - |
|
97 | - return ($pastLength > 20 ? '...' : '') . substr($this->input, max(0, $pastLength - 20), min(20, $pastLength)); |
|
98 | - } |
|
99 | - |
|
100 | - public function getUpcomingInput() |
|
101 | - { |
|
102 | - $next = $this->match; |
|
103 | - if (\strlen($next) < 20) { |
|
104 | - $next .= substr($this->input, $this->offset, 20 - \strlen($next)); |
|
105 | - } |
|
106 | - |
|
107 | - return substr($next, 0, 20) . (\strlen($next) > 20 ? '...' : ''); |
|
108 | - } |
|
109 | - |
|
110 | - public function getFullUpcomingInput() |
|
111 | - { |
|
112 | - $next = $this->match; |
|
113 | - if (substr($next, 0, 1) === '"' && substr_count($next, '"') === 1) { |
|
114 | - $len = \strlen($this->input); |
|
115 | - $strEnd = min(strpos($this->input, '"', $this->offset + 1) ?: $len, strpos($this->input, "\n", $this->offset + 1) ?: $len); |
|
116 | - $next .= substr($this->input, $this->offset, $strEnd - $this->offset); |
|
117 | - } elseif (\strlen($next) < 20) { |
|
118 | - $next .= substr($this->input, $this->offset, 20 - \strlen($next)); |
|
119 | - } |
|
120 | - |
|
121 | - return $next; |
|
122 | - } |
|
123 | - |
|
124 | - protected function parseError($str, $hash) |
|
125 | - { |
|
126 | - throw new \Exception($str); |
|
127 | - } |
|
128 | - |
|
129 | - private function next() |
|
130 | - { |
|
131 | - if ($this->done) { |
|
132 | - return $this->EOF; |
|
133 | - } |
|
134 | - if ($this->offset === \strlen($this->input)) { |
|
135 | - $this->done = true; |
|
136 | - } |
|
137 | - |
|
138 | - $token = null; |
|
139 | - $match = null; |
|
140 | - $col = null; |
|
141 | - $lines = null; |
|
142 | - |
|
143 | - if (!$this->more) { |
|
144 | - $this->yytext = ''; |
|
145 | - $this->match = ''; |
|
146 | - } |
|
147 | - |
|
148 | - $rules = $this->getCurrentRules(); |
|
149 | - $rulesLen = \count($rules); |
|
150 | - |
|
151 | - for ($i=0; $i < $rulesLen; $i++) { |
|
152 | - if (preg_match($this->rules[$rules[$i]], $this->input, $match, 0, $this->offset)) { |
|
153 | - preg_match_all('/\n.*/', $match[0], $lines); |
|
154 | - $lines = $lines[0]; |
|
155 | - if ($lines) { |
|
156 | - $this->yylineno += \count($lines); |
|
157 | - } |
|
158 | - |
|
159 | - $this->yylloc = array( |
|
160 | - 'first_line' => $this->yylloc['last_line'], |
|
161 | - 'last_line' => $this->yylineno+1, |
|
162 | - 'first_column' => $this->yylloc['last_column'], |
|
163 | - 'last_column' => $lines ? \strlen($lines[\count($lines) - 1]) - 1 : $this->yylloc['last_column'] + \strlen($match[0]), |
|
164 | - ); |
|
165 | - $this->yytext .= $match[0]; |
|
166 | - $this->match .= $match[0]; |
|
167 | - $this->yyleng = \strlen($this->yytext); |
|
168 | - $this->more = false; |
|
169 | - $this->offset += \strlen($match[0]); |
|
170 | - $token = $this->performAction($rules[$i], $this->conditionStack[\count($this->conditionStack)-1]); |
|
171 | - if ($token) { |
|
172 | - return $token; |
|
173 | - } |
|
174 | - |
|
175 | - return new Undefined(); |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - if ($this->offset === \strlen($this->input)) { |
|
180 | - return $this->EOF; |
|
181 | - } |
|
182 | - |
|
183 | - $this->parseError( |
|
184 | - 'Lexical error on line ' . ($this->yylineno+1) . ". Unrecognized text.\n" . $this->showPosition(), |
|
185 | - array( |
|
186 | - 'text' => "", |
|
187 | - 'token' => null, |
|
188 | - 'line' => $this->yylineno, |
|
189 | - ) |
|
190 | - ); |
|
191 | - } |
|
192 | - |
|
193 | - private function getCurrentRules() |
|
194 | - { |
|
195 | - return $this->conditions[$this->conditionStack[\count($this->conditionStack)-1]]['rules']; |
|
196 | - } |
|
197 | - |
|
198 | - private function performAction($avoiding_name_collisions, $YY_START) |
|
199 | - { |
|
200 | - switch ($avoiding_name_collisions) { |
|
201 | - case 0:/* skip whitespace */ |
|
202 | - break; |
|
203 | - case 1: |
|
204 | - return 6; |
|
205 | - case 2: |
|
206 | - $this->yytext = substr($this->yytext, 1, $this->yyleng-2); |
|
207 | - |
|
208 | - return 4; |
|
209 | - case 3: |
|
210 | - return 17; |
|
211 | - case 4: |
|
212 | - return 18; |
|
213 | - case 5: |
|
214 | - return 23; |
|
215 | - case 6: |
|
216 | - return 24; |
|
217 | - case 7: |
|
218 | - return 22; |
|
219 | - case 8: |
|
220 | - return 21; |
|
221 | - case 9: |
|
222 | - return 10; |
|
223 | - case 10: |
|
224 | - return 11; |
|
225 | - case 11: |
|
226 | - return 8; |
|
227 | - case 12: |
|
228 | - return 14; |
|
229 | - case 13: |
|
230 | - return 'INVALID'; |
|
231 | - } |
|
232 | - } |
|
21 | + private $EOF = 1; |
|
22 | + /** |
|
23 | + * @phpstan-var array<int, string> |
|
24 | + */ |
|
25 | + private $rules = array( |
|
26 | + 0 => '/\G\s+/', |
|
27 | + 1 => '/\G-?([0-9]|[1-9][0-9]+)(\.[0-9]+)?([eE][+-]?[0-9]+)?\b/', |
|
28 | + 2 => '{\G"(?>\\\\["bfnrt/\\\\]|\\\\u[a-fA-F0-9]{4}|[^\0-\x1f\\\\"]++)*+"}', |
|
29 | + 3 => '/\G\{/', |
|
30 | + 4 => '/\G\}/', |
|
31 | + 5 => '/\G\[/', |
|
32 | + 6 => '/\G\]/', |
|
33 | + 7 => '/\G,/', |
|
34 | + 8 => '/\G:/', |
|
35 | + 9 => '/\Gtrue\b/', |
|
36 | + 10 => '/\Gfalse\b/', |
|
37 | + 11 => '/\Gnull\b/', |
|
38 | + 12 => '/\G$/', |
|
39 | + 13 => '/\G./', |
|
40 | + ); |
|
41 | + |
|
42 | + private $conditions = array( |
|
43 | + "INITIAL" => array( |
|
44 | + "rules" => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13), |
|
45 | + "inclusive" => true, |
|
46 | + ), |
|
47 | + ); |
|
48 | + |
|
49 | + private $conditionStack; |
|
50 | + private $input; |
|
51 | + private $more; |
|
52 | + private $done; |
|
53 | + private $offset; |
|
54 | + |
|
55 | + public $match; |
|
56 | + public $yylineno; |
|
57 | + public $yyleng; |
|
58 | + public $yytext; |
|
59 | + public $yylloc; |
|
60 | + |
|
61 | + public function lex() |
|
62 | + { |
|
63 | + $r = $this->next(); |
|
64 | + if (!$r instanceof Undefined) { |
|
65 | + return $r; |
|
66 | + } |
|
67 | + |
|
68 | + return $this->lex(); |
|
69 | + } |
|
70 | + |
|
71 | + public function setInput($input) |
|
72 | + { |
|
73 | + $this->input = $input; |
|
74 | + $this->more = false; |
|
75 | + $this->done = false; |
|
76 | + $this->offset = 0; |
|
77 | + $this->yylineno = $this->yyleng = 0; |
|
78 | + $this->yytext = $this->match = ''; |
|
79 | + $this->conditionStack = array('INITIAL'); |
|
80 | + $this->yylloc = array('first_line' => 1, 'first_column' => 0, 'last_line' => 1, 'last_column' => 0); |
|
81 | + |
|
82 | + return $this; |
|
83 | + } |
|
84 | + |
|
85 | + public function showPosition() |
|
86 | + { |
|
87 | + $pre = str_replace("\n", '', $this->getPastInput()); |
|
88 | + $c = str_repeat('-', max(0, \strlen($pre) - 1)); // new Array(pre.length + 1).join("-"); |
|
89 | + |
|
90 | + return $pre . str_replace("\n", '', $this->getUpcomingInput()) . "\n" . $c . "^"; |
|
91 | + } |
|
92 | + |
|
93 | + public function getPastInput() |
|
94 | + { |
|
95 | + $pastLength = $this->offset - \strlen($this->match); |
|
96 | + |
|
97 | + return ($pastLength > 20 ? '...' : '') . substr($this->input, max(0, $pastLength - 20), min(20, $pastLength)); |
|
98 | + } |
|
99 | + |
|
100 | + public function getUpcomingInput() |
|
101 | + { |
|
102 | + $next = $this->match; |
|
103 | + if (\strlen($next) < 20) { |
|
104 | + $next .= substr($this->input, $this->offset, 20 - \strlen($next)); |
|
105 | + } |
|
106 | + |
|
107 | + return substr($next, 0, 20) . (\strlen($next) > 20 ? '...' : ''); |
|
108 | + } |
|
109 | + |
|
110 | + public function getFullUpcomingInput() |
|
111 | + { |
|
112 | + $next = $this->match; |
|
113 | + if (substr($next, 0, 1) === '"' && substr_count($next, '"') === 1) { |
|
114 | + $len = \strlen($this->input); |
|
115 | + $strEnd = min(strpos($this->input, '"', $this->offset + 1) ?: $len, strpos($this->input, "\n", $this->offset + 1) ?: $len); |
|
116 | + $next .= substr($this->input, $this->offset, $strEnd - $this->offset); |
|
117 | + } elseif (\strlen($next) < 20) { |
|
118 | + $next .= substr($this->input, $this->offset, 20 - \strlen($next)); |
|
119 | + } |
|
120 | + |
|
121 | + return $next; |
|
122 | + } |
|
123 | + |
|
124 | + protected function parseError($str, $hash) |
|
125 | + { |
|
126 | + throw new \Exception($str); |
|
127 | + } |
|
128 | + |
|
129 | + private function next() |
|
130 | + { |
|
131 | + if ($this->done) { |
|
132 | + return $this->EOF; |
|
133 | + } |
|
134 | + if ($this->offset === \strlen($this->input)) { |
|
135 | + $this->done = true; |
|
136 | + } |
|
137 | + |
|
138 | + $token = null; |
|
139 | + $match = null; |
|
140 | + $col = null; |
|
141 | + $lines = null; |
|
142 | + |
|
143 | + if (!$this->more) { |
|
144 | + $this->yytext = ''; |
|
145 | + $this->match = ''; |
|
146 | + } |
|
147 | + |
|
148 | + $rules = $this->getCurrentRules(); |
|
149 | + $rulesLen = \count($rules); |
|
150 | + |
|
151 | + for ($i=0; $i < $rulesLen; $i++) { |
|
152 | + if (preg_match($this->rules[$rules[$i]], $this->input, $match, 0, $this->offset)) { |
|
153 | + preg_match_all('/\n.*/', $match[0], $lines); |
|
154 | + $lines = $lines[0]; |
|
155 | + if ($lines) { |
|
156 | + $this->yylineno += \count($lines); |
|
157 | + } |
|
158 | + |
|
159 | + $this->yylloc = array( |
|
160 | + 'first_line' => $this->yylloc['last_line'], |
|
161 | + 'last_line' => $this->yylineno+1, |
|
162 | + 'first_column' => $this->yylloc['last_column'], |
|
163 | + 'last_column' => $lines ? \strlen($lines[\count($lines) - 1]) - 1 : $this->yylloc['last_column'] + \strlen($match[0]), |
|
164 | + ); |
|
165 | + $this->yytext .= $match[0]; |
|
166 | + $this->match .= $match[0]; |
|
167 | + $this->yyleng = \strlen($this->yytext); |
|
168 | + $this->more = false; |
|
169 | + $this->offset += \strlen($match[0]); |
|
170 | + $token = $this->performAction($rules[$i], $this->conditionStack[\count($this->conditionStack)-1]); |
|
171 | + if ($token) { |
|
172 | + return $token; |
|
173 | + } |
|
174 | + |
|
175 | + return new Undefined(); |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + if ($this->offset === \strlen($this->input)) { |
|
180 | + return $this->EOF; |
|
181 | + } |
|
182 | + |
|
183 | + $this->parseError( |
|
184 | + 'Lexical error on line ' . ($this->yylineno+1) . ". Unrecognized text.\n" . $this->showPosition(), |
|
185 | + array( |
|
186 | + 'text' => "", |
|
187 | + 'token' => null, |
|
188 | + 'line' => $this->yylineno, |
|
189 | + ) |
|
190 | + ); |
|
191 | + } |
|
192 | + |
|
193 | + private function getCurrentRules() |
|
194 | + { |
|
195 | + return $this->conditions[$this->conditionStack[\count($this->conditionStack)-1]]['rules']; |
|
196 | + } |
|
197 | + |
|
198 | + private function performAction($avoiding_name_collisions, $YY_START) |
|
199 | + { |
|
200 | + switch ($avoiding_name_collisions) { |
|
201 | + case 0:/* skip whitespace */ |
|
202 | + break; |
|
203 | + case 1: |
|
204 | + return 6; |
|
205 | + case 2: |
|
206 | + $this->yytext = substr($this->yytext, 1, $this->yyleng-2); |
|
207 | + |
|
208 | + return 4; |
|
209 | + case 3: |
|
210 | + return 17; |
|
211 | + case 4: |
|
212 | + return 18; |
|
213 | + case 5: |
|
214 | + return 23; |
|
215 | + case 6: |
|
216 | + return 24; |
|
217 | + case 7: |
|
218 | + return 22; |
|
219 | + case 8: |
|
220 | + return 21; |
|
221 | + case 9: |
|
222 | + return 10; |
|
223 | + case 10: |
|
224 | + return 11; |
|
225 | + case 11: |
|
226 | + return 8; |
|
227 | + case 12: |
|
228 | + return 14; |
|
229 | + case 13: |
|
230 | + return 'INVALID'; |
|
231 | + } |
|
232 | + } |
|
233 | 233 | } |
@@ -198,36 +198,36 @@ |
||
198 | 198 | private function performAction($avoiding_name_collisions, $YY_START) |
199 | 199 | { |
200 | 200 | switch ($avoiding_name_collisions) { |
201 | - case 0:/* skip whitespace */ |
|
202 | - break; |
|
203 | - case 1: |
|
204 | - return 6; |
|
205 | - case 2: |
|
206 | - $this->yytext = substr($this->yytext, 1, $this->yyleng-2); |
|
207 | - |
|
208 | - return 4; |
|
209 | - case 3: |
|
210 | - return 17; |
|
211 | - case 4: |
|
212 | - return 18; |
|
213 | - case 5: |
|
214 | - return 23; |
|
215 | - case 6: |
|
216 | - return 24; |
|
217 | - case 7: |
|
218 | - return 22; |
|
219 | - case 8: |
|
220 | - return 21; |
|
221 | - case 9: |
|
222 | - return 10; |
|
223 | - case 10: |
|
224 | - return 11; |
|
225 | - case 11: |
|
226 | - return 8; |
|
227 | - case 12: |
|
228 | - return 14; |
|
229 | - case 13: |
|
230 | - return 'INVALID'; |
|
201 | + case 0:/* skip whitespace */ |
|
202 | + break; |
|
203 | + case 1: |
|
204 | + return 6; |
|
205 | + case 2: |
|
206 | + $this->yytext = substr($this->yytext, 1, $this->yyleng-2); |
|
207 | + |
|
208 | + return 4; |
|
209 | + case 3: |
|
210 | + return 17; |
|
211 | + case 4: |
|
212 | + return 18; |
|
213 | + case 5: |
|
214 | + return 23; |
|
215 | + case 6: |
|
216 | + return 24; |
|
217 | + case 7: |
|
218 | + return 22; |
|
219 | + case 8: |
|
220 | + return 21; |
|
221 | + case 9: |
|
222 | + return 10; |
|
223 | + case 10: |
|
224 | + return 11; |
|
225 | + case 11: |
|
226 | + return 8; |
|
227 | + case 12: |
|
228 | + return 14; |
|
229 | + case 13: |
|
230 | + return 'INVALID'; |
|
231 | 231 | } |
232 | 232 | } |
233 | 233 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | |
42 | 42 | private $conditions = array( |
43 | 43 | "INITIAL" => array( |
44 | - "rules" => array(0,1,2,3,4,5,6,7,8,9,10,11,12,13), |
|
44 | + "rules" => array( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ), |
|
45 | 45 | "inclusive" => true, |
46 | 46 | ), |
47 | 47 | ); |
@@ -61,14 +61,14 @@ discard block |
||
61 | 61 | public function lex() |
62 | 62 | { |
63 | 63 | $r = $this->next(); |
64 | - if (!$r instanceof Undefined) { |
|
64 | + if ( ! $r instanceof Undefined ) { |
|
65 | 65 | return $r; |
66 | 66 | } |
67 | 67 | |
68 | 68 | return $this->lex(); |
69 | 69 | } |
70 | 70 | |
71 | - public function setInput($input) |
|
71 | + public function setInput( $input ) |
|
72 | 72 | { |
73 | 73 | $this->input = $input; |
74 | 74 | $this->more = false; |
@@ -76,62 +76,62 @@ discard block |
||
76 | 76 | $this->offset = 0; |
77 | 77 | $this->yylineno = $this->yyleng = 0; |
78 | 78 | $this->yytext = $this->match = ''; |
79 | - $this->conditionStack = array('INITIAL'); |
|
80 | - $this->yylloc = array('first_line' => 1, 'first_column' => 0, 'last_line' => 1, 'last_column' => 0); |
|
79 | + $this->conditionStack = array( 'INITIAL' ); |
|
80 | + $this->yylloc = array( 'first_line' => 1, 'first_column' => 0, 'last_line' => 1, 'last_column' => 0 ); |
|
81 | 81 | |
82 | 82 | return $this; |
83 | 83 | } |
84 | 84 | |
85 | 85 | public function showPosition() |
86 | 86 | { |
87 | - $pre = str_replace("\n", '', $this->getPastInput()); |
|
88 | - $c = str_repeat('-', max(0, \strlen($pre) - 1)); // new Array(pre.length + 1).join("-"); |
|
87 | + $pre = str_replace( "\n", '', $this->getPastInput() ); |
|
88 | + $c = str_repeat( '-', max( 0, \strlen( $pre ) - 1 ) ); // new Array(pre.length + 1).join("-"); |
|
89 | 89 | |
90 | - return $pre . str_replace("\n", '', $this->getUpcomingInput()) . "\n" . $c . "^"; |
|
90 | + return $pre . str_replace( "\n", '', $this->getUpcomingInput() ) . "\n" . $c . "^"; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | public function getPastInput() |
94 | 94 | { |
95 | - $pastLength = $this->offset - \strlen($this->match); |
|
95 | + $pastLength = $this->offset - \strlen( $this->match ); |
|
96 | 96 | |
97 | - return ($pastLength > 20 ? '...' : '') . substr($this->input, max(0, $pastLength - 20), min(20, $pastLength)); |
|
97 | + return ( $pastLength > 20 ? '...' : '' ) . substr( $this->input, max( 0, $pastLength - 20 ), min( 20, $pastLength ) ); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | public function getUpcomingInput() |
101 | 101 | { |
102 | 102 | $next = $this->match; |
103 | - if (\strlen($next) < 20) { |
|
104 | - $next .= substr($this->input, $this->offset, 20 - \strlen($next)); |
|
103 | + if ( \strlen( $next ) < 20 ) { |
|
104 | + $next .= substr( $this->input, $this->offset, 20 - \strlen( $next ) ); |
|
105 | 105 | } |
106 | 106 | |
107 | - return substr($next, 0, 20) . (\strlen($next) > 20 ? '...' : ''); |
|
107 | + return substr( $next, 0, 20 ) . ( \strlen( $next ) > 20 ? '...' : '' ); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | public function getFullUpcomingInput() |
111 | 111 | { |
112 | 112 | $next = $this->match; |
113 | - if (substr($next, 0, 1) === '"' && substr_count($next, '"') === 1) { |
|
114 | - $len = \strlen($this->input); |
|
115 | - $strEnd = min(strpos($this->input, '"', $this->offset + 1) ?: $len, strpos($this->input, "\n", $this->offset + 1) ?: $len); |
|
116 | - $next .= substr($this->input, $this->offset, $strEnd - $this->offset); |
|
117 | - } elseif (\strlen($next) < 20) { |
|
118 | - $next .= substr($this->input, $this->offset, 20 - \strlen($next)); |
|
113 | + if ( substr( $next, 0, 1 ) === '"' && substr_count( $next, '"' ) === 1 ) { |
|
114 | + $len = \strlen( $this->input ); |
|
115 | + $strEnd = min( strpos( $this->input, '"', $this->offset + 1 ) ?: $len, strpos( $this->input, "\n", $this->offset + 1 ) ?: $len ); |
|
116 | + $next .= substr( $this->input, $this->offset, $strEnd - $this->offset ); |
|
117 | + } elseif ( \strlen( $next ) < 20 ) { |
|
118 | + $next .= substr( $this->input, $this->offset, 20 - \strlen( $next ) ); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | return $next; |
122 | 122 | } |
123 | 123 | |
124 | - protected function parseError($str, $hash) |
|
124 | + protected function parseError( $str, $hash ) |
|
125 | 125 | { |
126 | - throw new \Exception($str); |
|
126 | + throw new \Exception( $str ); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | private function next() |
130 | 130 | { |
131 | - if ($this->done) { |
|
131 | + if ( $this->done ) { |
|
132 | 132 | return $this->EOF; |
133 | 133 | } |
134 | - if ($this->offset === \strlen($this->input)) { |
|
134 | + if ( $this->offset === \strlen( $this->input ) ) { |
|
135 | 135 | $this->done = true; |
136 | 136 | } |
137 | 137 | |
@@ -140,35 +140,35 @@ discard block |
||
140 | 140 | $col = null; |
141 | 141 | $lines = null; |
142 | 142 | |
143 | - if (!$this->more) { |
|
143 | + if ( ! $this->more ) { |
|
144 | 144 | $this->yytext = ''; |
145 | 145 | $this->match = ''; |
146 | 146 | } |
147 | 147 | |
148 | 148 | $rules = $this->getCurrentRules(); |
149 | - $rulesLen = \count($rules); |
|
150 | - |
|
151 | - for ($i=0; $i < $rulesLen; $i++) { |
|
152 | - if (preg_match($this->rules[$rules[$i]], $this->input, $match, 0, $this->offset)) { |
|
153 | - preg_match_all('/\n.*/', $match[0], $lines); |
|
154 | - $lines = $lines[0]; |
|
155 | - if ($lines) { |
|
156 | - $this->yylineno += \count($lines); |
|
149 | + $rulesLen = \count( $rules ); |
|
150 | + |
|
151 | + for ( $i = 0; $i < $rulesLen; $i++ ) { |
|
152 | + if ( preg_match( $this->rules[ $rules[ $i ] ], $this->input, $match, 0, $this->offset ) ) { |
|
153 | + preg_match_all( '/\n.*/', $match[ 0 ], $lines ); |
|
154 | + $lines = $lines[ 0 ]; |
|
155 | + if ( $lines ) { |
|
156 | + $this->yylineno += \count( $lines ); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | $this->yylloc = array( |
160 | - 'first_line' => $this->yylloc['last_line'], |
|
161 | - 'last_line' => $this->yylineno+1, |
|
162 | - 'first_column' => $this->yylloc['last_column'], |
|
163 | - 'last_column' => $lines ? \strlen($lines[\count($lines) - 1]) - 1 : $this->yylloc['last_column'] + \strlen($match[0]), |
|
160 | + 'first_line' => $this->yylloc[ 'last_line' ], |
|
161 | + 'last_line' => $this->yylineno + 1, |
|
162 | + 'first_column' => $this->yylloc[ 'last_column' ], |
|
163 | + 'last_column' => $lines ? \strlen( $lines[ \count( $lines ) - 1 ] ) - 1 : $this->yylloc[ 'last_column' ] + \strlen( $match[ 0 ] ), |
|
164 | 164 | ); |
165 | - $this->yytext .= $match[0]; |
|
166 | - $this->match .= $match[0]; |
|
167 | - $this->yyleng = \strlen($this->yytext); |
|
165 | + $this->yytext .= $match[ 0 ]; |
|
166 | + $this->match .= $match[ 0 ]; |
|
167 | + $this->yyleng = \strlen( $this->yytext ); |
|
168 | 168 | $this->more = false; |
169 | - $this->offset += \strlen($match[0]); |
|
170 | - $token = $this->performAction($rules[$i], $this->conditionStack[\count($this->conditionStack)-1]); |
|
171 | - if ($token) { |
|
169 | + $this->offset += \strlen( $match[ 0 ] ); |
|
170 | + $token = $this->performAction( $rules[ $i ], $this->conditionStack[ \count( $this->conditionStack ) - 1 ] ); |
|
171 | + if ( $token ) { |
|
172 | 172 | return $token; |
173 | 173 | } |
174 | 174 | |
@@ -176,12 +176,12 @@ discard block |
||
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
179 | - if ($this->offset === \strlen($this->input)) { |
|
179 | + if ( $this->offset === \strlen( $this->input ) ) { |
|
180 | 180 | return $this->EOF; |
181 | 181 | } |
182 | 182 | |
183 | 183 | $this->parseError( |
184 | - 'Lexical error on line ' . ($this->yylineno+1) . ". Unrecognized text.\n" . $this->showPosition(), |
|
184 | + 'Lexical error on line ' . ( $this->yylineno + 1 ) . ". Unrecognized text.\n" . $this->showPosition(), |
|
185 | 185 | array( |
186 | 186 | 'text' => "", |
187 | 187 | 'token' => null, |
@@ -192,18 +192,18 @@ discard block |
||
192 | 192 | |
193 | 193 | private function getCurrentRules() |
194 | 194 | { |
195 | - return $this->conditions[$this->conditionStack[\count($this->conditionStack)-1]]['rules']; |
|
195 | + return $this->conditions[ $this->conditionStack[ \count( $this->conditionStack ) - 1 ] ][ 'rules' ]; |
|
196 | 196 | } |
197 | 197 | |
198 | - private function performAction($avoiding_name_collisions, $YY_START) |
|
198 | + private function performAction( $avoiding_name_collisions, $YY_START ) |
|
199 | 199 | { |
200 | - switch ($avoiding_name_collisions) { |
|
200 | + switch ( $avoiding_name_collisions ) { |
|
201 | 201 | case 0:/* skip whitespace */ |
202 | 202 | break; |
203 | 203 | case 1: |
204 | 204 | return 6; |
205 | 205 | case 2: |
206 | - $this->yytext = substr($this->yytext, 1, $this->yyleng-2); |
|
206 | + $this->yytext = substr( $this->yytext, 1, $this->yyleng - 2 ); |
|
207 | 207 | |
208 | 208 | return 4; |
209 | 209 | case 3: |
@@ -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 | } |
@@ -13,23 +13,23 @@ |
||
13 | 13 | |
14 | 14 | class ParsingException extends \Exception |
15 | 15 | { |
16 | - protected $details; |
|
16 | + protected $details; |
|
17 | 17 | |
18 | - /** |
|
19 | - * @param string $message |
|
20 | - * @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 | - */ |
|
22 | - public function __construct($message, $details = array()) |
|
23 | - { |
|
24 | - $this->details = $details; |
|
25 | - parent::__construct($message); |
|
26 | - } |
|
18 | + /** |
|
19 | + * @param string $message |
|
20 | + * @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 | + */ |
|
22 | + public function __construct($message, $details = array()) |
|
23 | + { |
|
24 | + $this->details = $details; |
|
25 | + parent::__construct($message); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @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 | - */ |
|
31 | - public function getDetails() |
|
32 | - { |
|
33 | - return $this->details; |
|
34 | - } |
|
28 | + /** |
|
29 | + * @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 | + */ |
|
31 | + public function getDetails() |
|
32 | + { |
|
33 | + return $this->details; |
|
34 | + } |
|
35 | 35 | } |
@@ -19,10 +19,10 @@ |
||
19 | 19 | * @param string $message |
20 | 20 | * @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 | 21 | */ |
22 | - public function __construct($message, $details = array()) |
|
22 | + public function __construct( $message, $details = array() ) |
|
23 | 23 | { |
24 | 24 | $this->details = $details; |
25 | - parent::__construct($message); |
|
25 | + parent::__construct( $message ); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -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 | } |
@@ -9,28 +9,28 @@ |
||
9 | 9 | */ |
10 | 10 | interface ContainerInterface |
11 | 11 | { |
12 | - /** |
|
13 | - * Finds an entry of the container by its identifier and returns it. |
|
14 | - * |
|
15 | - * @param string $id Identifier of the entry to look for. |
|
16 | - * |
|
17 | - * @throws NotFoundExceptionInterface No entry was found for **this** identifier. |
|
18 | - * @throws ContainerExceptionInterface Error while retrieving the entry. |
|
19 | - * |
|
20 | - * @return mixed Entry. |
|
21 | - */ |
|
22 | - public function get(string $id); |
|
12 | + /** |
|
13 | + * Finds an entry of the container by its identifier and returns it. |
|
14 | + * |
|
15 | + * @param string $id Identifier of the entry to look for. |
|
16 | + * |
|
17 | + * @throws NotFoundExceptionInterface No entry was found for **this** identifier. |
|
18 | + * @throws ContainerExceptionInterface Error while retrieving the entry. |
|
19 | + * |
|
20 | + * @return mixed Entry. |
|
21 | + */ |
|
22 | + public function get(string $id); |
|
23 | 23 | |
24 | - /** |
|
25 | - * Returns true if the container can return an entry for the given identifier. |
|
26 | - * Returns false otherwise. |
|
27 | - * |
|
28 | - * `has($id)` returning true does not mean that `get($id)` will not throw an exception. |
|
29 | - * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`. |
|
30 | - * |
|
31 | - * @param string $id Identifier of the entry to look for. |
|
32 | - * |
|
33 | - * @return bool |
|
34 | - */ |
|
35 | - public function has(string $id); |
|
24 | + /** |
|
25 | + * Returns true if the container can return an entry for the given identifier. |
|
26 | + * Returns false otherwise. |
|
27 | + * |
|
28 | + * `has($id)` returning true does not mean that `get($id)` will not throw an exception. |
|
29 | + * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`. |
|
30 | + * |
|
31 | + * @param string $id Identifier of the entry to look for. |
|
32 | + * |
|
33 | + * @return bool |
|
34 | + */ |
|
35 | + public function has(string $id); |
|
36 | 36 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @return mixed Entry. |
21 | 21 | */ |
22 | - public function get(string $id); |
|
22 | + public function get( string $id ); |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * Returns true if the container can return an entry for the given identifier. |
@@ -32,5 +32,5 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return bool |
34 | 34 | */ |
35 | - public function has(string $id); |
|
35 | + public function has( string $id ); |
|
36 | 36 | } |
@@ -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 | * |