Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#1)
by Der Mundschenk
04:16
created
src/bin/class-pattern-converter.php 1 patch
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -63,14 +63,14 @@  discard block
 block discarded – undo
63 63
 	 * @param string $url      The TeX pattern file URL.
64 64
 	 * @param string $language A human-readable language name.
65 65
 	 */
66
-	public function __construct( $url, $language ) {
66
+	public function __construct($url, $language) {
67 67
 		$this->url      = $url;
68 68
 		$this->language = $language;
69 69
 
70
-		$this->word_characters = join( [
70
+		$this->word_characters = join([
71 71
 			"\w.'ʼ᾽ʼ᾿’",
72
-			Strings::uchr( 8205, 8204, 768, 769, 771, 772, 775, 776, 784, 803, 805, 814, 817 ),
73
-			'\p{Devanagari}' . Strings::uchr( 2385, 2386 ),
72
+			Strings::uchr(8205, 8204, 768, 769, 771, 772, 775, 776, 784, 803, 805, 814, 817),
73
+			'\p{Devanagari}' . Strings::uchr(2385, 2386),
74 74
 			'\p{Bengali}',
75 75
 			'\p{Gujarati}',
76 76
 			'\p{Gurmukhi}',
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 			'\p{Malayalam}',
82 82
 			'\p{Thai}',
83 83
 			'-',
84
-		] );
84
+		]);
85 85
 	}
86 86
 
87 87
 	/**
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
 	 * @param string $pattern TeX hyphenation pattern.
91 91
 	 * @return string
92 92
 	 */
93
-	protected function get_segment( $pattern ) {
94
-		return preg_replace( '/[0-9]/', '', str_replace( '.', '_', $pattern ) );
93
+	protected function get_segment($pattern) {
94
+		return preg_replace('/[0-9]/', '', str_replace('.', '_', $pattern));
95 95
 	}
96 96
 
97 97
 	/**
@@ -101,31 +101,31 @@  discard block
 block discarded – undo
101 101
 	 *
102 102
 	 * @return string|null Script exits on error.
103 103
 	 */
104
-	protected function get_sequence( $pattern ) {
105
-		$characters = Strings::mb_str_split( str_replace( '.', '_', $pattern ) );
104
+	protected function get_sequence($pattern) {
105
+		$characters = Strings::mb_str_split(str_replace('.', '_', $pattern));
106 106
 		$result = [];
107 107
 
108
-		foreach ( $characters as $index => $chr ) {
109
-			if ( ctype_digit( $chr ) ) {
108
+		foreach ($characters as $index => $chr) {
109
+			if (ctype_digit($chr)) {
110 110
 				$result[] = $chr;
111 111
 			} else {
112
-				if ( ! isset( $characters[ $index - 1 ] ) || ! ctype_digit( $characters[ $index - 1 ] ) ) {
112
+				if ( ! isset($characters[$index - 1]) || ! ctype_digit($characters[$index - 1])) {
113 113
 					$result[] = '0';
114 114
 				}
115 115
 
116
-				if ( ! isset( $characters[ $index + 1 ] ) && ! ctype_digit( $characters[ $index ] ) ) {
116
+				if ( ! isset($characters[$index + 1]) && ! ctype_digit($characters[$index])) {
117 117
 					$result[] = '0';
118 118
 				}
119 119
 			}
120 120
 		}
121 121
 
122 122
 		// Do some error checking.
123
-		$count = count( $result );
124
-		$count_seg = mb_strlen( $this->get_segment( $pattern ) );
125
-		$sequence = implode( $result );
123
+		$count = count($result);
124
+		$count_seg = mb_strlen($this->get_segment($pattern));
125
+		$sequence = implode($result);
126 126
 
127
-		if ( $count !== $count_seg + 1 ) {
128
-			trigger_error( "Invalid segment length $count for pattern $pattern (result sequence $sequence)", E_USER_ERROR ); // @codingStandardsIgnoreLine
127
+		if ($count !== $count_seg + 1) {
128
+			trigger_error("Invalid segment length $count for pattern $pattern (result sequence $sequence)", E_USER_ERROR); // @codingStandardsIgnoreLine
129 129
 
130 130
 			die( -3000 );
131 131
 		}
@@ -146,32 +146,32 @@  discard block
 block discarded – undo
146 146
 	 *
147 147
 	 * @return string
148 148
 	 */
149
-	protected function format_results( array $patterns, array $exceptions, array $comments ) {
149
+	protected function format_results(array $patterns, array $exceptions, array $comments) {
150 150
 		$pattern_mapping = [];
151 151
 
152
-		foreach ( $patterns as $pattern ) {
153
-			$segment = $this->get_segment( $pattern );
152
+		foreach ($patterns as $pattern) {
153
+			$segment = $this->get_segment($pattern);
154 154
 
155
-			if ( ! isset( $pattern_mapping[ $segment ] ) ) {
156
-				$pattern_mapping[ $segment ] = $this->get_sequence( $pattern );
155
+			if ( ! isset($pattern_mapping[$segment])) {
156
+				$pattern_mapping[$segment] = $this->get_sequence($pattern);
157 157
 			}
158 158
 		}
159 159
 
160 160
 		// Produce a nice exceptions mapping.
161 161
 		$json_exceptions = [];
162
-		foreach ( $exceptions as $exception ) {
163
-			$json_exceptions[ mb_strtolower( str_replace( '-', '', $exception ) ) ] = mb_strtolower( $exception );
162
+		foreach ($exceptions as $exception) {
163
+			$json_exceptions[mb_strtolower(str_replace('-', '', $exception))] = mb_strtolower($exception);
164 164
 		}
165 165
 
166 166
 		$json_results = [
167 167
 			'language'         => $this->language,
168 168
 			'source_url'       => $this->url,
169
-			'copyright'        => array_map( 'rtrim', $comments ),
169
+			'copyright'        => array_map('rtrim', $comments),
170 170
 			'exceptions'       => $json_exceptions,
171 171
 			'patterns'         => $pattern_mapping,
172 172
 		];
173 173
 
174
-		return json_encode( $json_results, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE );
174
+		return json_encode($json_results, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
175 175
 	}
176 176
 
177 177
 	/**
@@ -188,27 +188,27 @@  discard block
 block discarded – undo
188 188
 	 *
189 189
 	 * @return bool
190 190
 	 */
191
-	protected function match_exceptions( $line, array &$exceptions ) {
192
-		if ( preg_match( '/^\s*([\w-]+)\s*}\s*(?:%.*)?$/u', $line, $matches ) ) {
191
+	protected function match_exceptions($line, array &$exceptions) {
192
+		if (preg_match('/^\s*([\w-]+)\s*}\s*(?:%.*)?$/u', $line, $matches)) {
193 193
 			$exceptions[] = $matches[1];
194 194
 			return false;
195
-		} if ( preg_match( '/^\s*((?:[\w-]+\s*)+)\s*}\s*(?:%.*)?$/u', $line, $matches ) ) {
196
-			$this->match_exceptions( $matches[1], $exceptions );
195
+		} if (preg_match('/^\s*((?:[\w-]+\s*)+)\s*}\s*(?:%.*)?$/u', $line, $matches)) {
196
+			$this->match_exceptions($matches[1], $exceptions);
197 197
 			return false;
198
-		} elseif ( preg_match( '/^\s*}\s*(?:%.*)?$/u', $line, $matches ) ) {
198
+		} elseif (preg_match('/^\s*}\s*(?:%.*)?$/u', $line, $matches)) {
199 199
 			return false;
200
-		} elseif ( preg_match( '/^\s*([\w-]+)\s*(?:%.*)?$/u',  $line, $matches ) ) {
200
+		} elseif (preg_match('/^\s*([\w-]+)\s*(?:%.*)?$/u', $line, $matches)) {
201 201
 			$exceptions[] = $matches[1];
202
-		} elseif ( preg_match( '/^\s*((?:[\w-]+\s*)+)(?:%.*)?$/u',  $line, $matches ) ) {
202
+		} elseif (preg_match('/^\s*((?:[\w-]+\s*)+)(?:%.*)?$/u', $line, $matches)) {
203 203
 			// Sometimes there are multiple exceptions on a single line.
204
-			foreach ( self::split_at_whitespace( $matches[1] ) as $match ) {
204
+			foreach (self::split_at_whitespace($matches[1]) as $match) {
205 205
 				$exceptions[] = $match;
206 206
 			}
207
-		} elseif ( preg_match( '/^\s*(?:%.*)?$/u', $line, $matches ) ) {
207
+		} elseif (preg_match('/^\s*(?:%.*)?$/u', $line, $matches)) {
208 208
 			// Ignore comments and whitespace in exceptions.
209 209
 			return true;
210 210
 		} else {
211
-			throw new RangeException( "Error: unknown exception line $line\n" );
211
+			throw new RangeException("Error: unknown exception line $line\n");
212 212
 		}
213 213
 
214 214
 		return true;
@@ -224,24 +224,24 @@  discard block
 block discarded – undo
224 224
 	 *
225 225
 	 * @return bool
226 226
 	 */
227
-	protected function match_patterns( $line, array &$patterns ) {
228
-		if ( preg_match( '/^\s*([' . $this->word_characters . ']+)\s*}\s*(?:%.*)?$/u', $line, $matches ) ) {
227
+	protected function match_patterns($line, array &$patterns) {
228
+		if (preg_match('/^\s*([' . $this->word_characters . ']+)\s*}\s*(?:%.*)?$/u', $line, $matches)) {
229 229
 			$patterns[] = $matches[1];
230 230
 			return false;
231
-		} elseif ( preg_match( '/^\s*}\s*(?:%.*)?$/u', $line, $matches ) ) {
231
+		} elseif (preg_match('/^\s*}\s*(?:%.*)?$/u', $line, $matches)) {
232 232
 			return false;
233
-		} elseif ( preg_match( '/^\s*([' . $this->word_characters . ']+)\s*(?:%.*)?$/u',  $line, $matches ) ) {
233
+		} elseif (preg_match('/^\s*([' . $this->word_characters . ']+)\s*(?:%.*)?$/u', $line, $matches)) {
234 234
 			$patterns[] = $matches[1];
235
-		} elseif ( preg_match( '/^\s*((?:[' . $this->word_characters . ']+\s*)+)(?:%.*)?$/u',  $line, $matches ) ) {
235
+		} elseif (preg_match('/^\s*((?:[' . $this->word_characters . ']+\s*)+)(?:%.*)?$/u', $line, $matches)) {
236 236
 			// Sometimes there are multiple patterns on a single line.
237
-			foreach ( self::split_at_whitespace( $matches[1] ) as $match ) {
237
+			foreach (self::split_at_whitespace($matches[1]) as $match) {
238 238
 				$patterns[] = $match;
239 239
 			}
240
-		} elseif ( preg_match( '/^\s*(?:%.*)?$/u', $line, $matches ) ) {
240
+		} elseif (preg_match('/^\s*(?:%.*)?$/u', $line, $matches)) {
241 241
 			// Ignore comments and whitespace in patterns.
242 242
 			return true;
243 243
 		} else {
244
-			throw new RangeException( 'Error: unknown pattern line ' . htmlentities( $line, ENT_NOQUOTES | ENT_HTML5 ) . "\n" );
244
+			throw new RangeException('Error: unknown pattern line ' . htmlentities($line, ENT_NOQUOTES | ENT_HTML5) . "\n");
245 245
 		}
246 246
 
247 247
 		return true;
@@ -254,8 +254,8 @@  discard block
 block discarded – undo
254 254
 	 *
255 255
 	 * @return array
256 256
 	 */
257
-	private static function split_at_whitespace( $line ) {
258
-		return preg_split( '/\s+/Su', $line, -1, PREG_SPLIT_NO_EMPTY );
257
+	private static function split_at_whitespace($line) {
258
+		return preg_split('/\s+/Su', $line, -1, PREG_SPLIT_NO_EMPTY);
259 259
 	}
260 260
 
261 261
 	/**
@@ -267,10 +267,10 @@  discard block
 block discarded – undo
267 267
 	 * @return string
268 268
 	 */
269 269
 	public function convert() {
270
-		if ( ! file_exists( $this->url ) ) {
271
-			$file_headers = @get_headers( $this->url );
272
-			if ( 'HTTP/1.0 404 Not Found' === $file_headers[0] ) {
273
-				throw new RuntimeException( "Error: unknown pattern file '{$this->url}'\n" );
270
+		if ( ! file_exists($this->url)) {
271
+			$file_headers = @get_headers($this->url);
272
+			if ('HTTP/1.0 404 Not Found' === $file_headers[0]) {
273
+				throw new RuntimeException("Error: unknown pattern file '{$this->url}'\n");
274 274
 			}
275 275
 		}
276 276
 
@@ -283,36 +283,36 @@  discard block
 block discarded – undo
283 283
 		$reading_patterns   = false;
284 284
 		$reading_exceptions = false;
285 285
 
286
-		$file = new \SplFileObject( $this->url );
287
-		while ( ! $file->eof() ) {
286
+		$file = new \SplFileObject($this->url);
287
+		while ( ! $file->eof()) {
288 288
 			$line = $file->fgets();
289 289
 
290
-			if ( $reading_patterns ) {
291
-				$reading_patterns = $this->match_patterns( $line, $patterns );
292
-			} elseif ( $reading_exceptions ) {
293
-				$reading_exceptions = $this->match_exceptions( $line, $exceptions );
290
+			if ($reading_patterns) {
291
+				$reading_patterns = $this->match_patterns($line, $patterns);
292
+			} elseif ($reading_exceptions) {
293
+				$reading_exceptions = $this->match_exceptions($line, $exceptions);
294 294
 			} else {
295 295
 				// Not a pattern & not an exception.
296
-				if ( preg_match( '/^\s*%.*$/u', $line, $matches ) ) {
296
+				if (preg_match('/^\s*%.*$/u', $line, $matches)) {
297 297
 					$comments[] = $line;
298
-				} elseif ( preg_match( '/^\s*\\\patterns\s*\{\s*(.*)$/u', $line, $matches ) ) {
299
-					$reading_patterns = $this->match_patterns( $matches[1], $patterns );
300
-				} elseif ( preg_match( '/^\s*\\\hyphenation\s*{\s*(.*)$/u', $line, $matches ) ) {
301
-					$reading_exceptions = $this->match_exceptions( $matches[1], $exceptions );
302
-				} elseif ( preg_match( '/^\s*\\\endinput.*$/u', $line, $matches ) ) {
298
+				} elseif (preg_match('/^\s*\\\patterns\s*\{\s*(.*)$/u', $line, $matches)) {
299
+					$reading_patterns = $this->match_patterns($matches[1], $patterns);
300
+				} elseif (preg_match('/^\s*\\\hyphenation\s*{\s*(.*)$/u', $line, $matches)) {
301
+					$reading_exceptions = $this->match_exceptions($matches[1], $exceptions);
302
+				} elseif (preg_match('/^\s*\\\endinput.*$/u', $line, $matches)) {
303 303
 					// Ignore this line completely.
304 304
 					continue;
305
-				} elseif ( preg_match( '/^\s*\\\[\w]+.*$/u', $line, $matches ) ) {
305
+				} elseif (preg_match('/^\s*\\\[\w]+.*$/u', $line, $matches)) {
306 306
 					// Treat other commands as comments unless we are matching exceptions or patterns.
307 307
 					$comments[] = $line;
308
-				} elseif ( preg_match( '/^\s*$/u', $line, $matches ) ) {
308
+				} elseif (preg_match('/^\s*$/u', $line, $matches)) {
309 309
 					continue; // Do nothing.
310 310
 				} else {
311
-					throw new RangeException( "Error: unknown line $line\n" );
311
+					throw new RangeException("Error: unknown line $line\n");
312 312
 				}
313 313
 			}
314 314
 		}
315 315
 
316
-		return $this->format_results( $patterns, $exceptions, $comments );
316
+		return $this->format_results($patterns, $exceptions, $comments);
317 317
 	}
318 318
 }
Please login to merge, or discard this patch.