We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -39,16 +39,16 @@ |
||
| 39 | 39 | * |
| 40 | 40 | * @return int |
| 41 | 41 | */ |
| 42 | - public static function get_http_response_code( $url ) { |
|
| 42 | + public static function get_http_response_code($url) { |
|
| 43 | 43 | |
| 44 | 44 | $curl = curl_init(); |
| 45 | - curl_setopt_array( $curl, [ |
|
| 45 | + curl_setopt_array($curl, [ |
|
| 46 | 46 | CURLOPT_RETURNTRANSFER => true, |
| 47 | 47 | CURLOPT_URL => $url, |
| 48 | - ] ); |
|
| 49 | - curl_exec( $curl ); |
|
| 50 | - $response_code = curl_getinfo( $curl, CURLINFO_HTTP_CODE ); |
|
| 51 | - curl_close( $curl ); |
|
| 48 | + ]); |
|
| 49 | + curl_exec($curl); |
|
| 50 | + $response_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
|
| 51 | + curl_close($curl); |
|
| 52 | 52 | |
| 53 | 53 | return $response_code; |
| 54 | 54 | } |
@@ -63,14 +63,14 @@ discard block |
||
| 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 |
||
| 81 | 81 | '\p{Malayalam}', |
| 82 | 82 | '\p{Thai}', |
| 83 | 83 | '-', |
| 84 | - ] ); |
|
| 84 | + ]); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -90,8 +90,8 @@ discard block |
||
| 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 | /** |
@@ -103,31 +103,31 @@ discard block |
||
| 103 | 103 | * |
| 104 | 104 | * @return string |
| 105 | 105 | */ |
| 106 | - protected function get_sequence( $pattern ) { |
|
| 107 | - $characters = Strings::mb_str_split( str_replace( '.', '_', $pattern ) ); |
|
| 106 | + protected function get_sequence($pattern) { |
|
| 107 | + $characters = Strings::mb_str_split(str_replace('.', '_', $pattern)); |
|
| 108 | 108 | $result = []; |
| 109 | 109 | |
| 110 | - foreach ( $characters as $index => $chr ) { |
|
| 111 | - if ( ctype_digit( $chr ) ) { |
|
| 110 | + foreach ($characters as $index => $chr) { |
|
| 111 | + if (ctype_digit($chr)) { |
|
| 112 | 112 | $result[] = $chr; |
| 113 | 113 | } else { |
| 114 | - if ( ! isset( $characters[ $index - 1 ] ) || ! ctype_digit( $characters[ $index - 1 ] ) ) { |
|
| 114 | + if ( ! isset($characters[$index - 1]) || ! ctype_digit($characters[$index - 1])) { |
|
| 115 | 115 | $result[] = '0'; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - if ( ! isset( $characters[ $index + 1 ] ) && ! ctype_digit( $characters[ $index ] ) ) { |
|
| 118 | + if ( ! isset($characters[$index + 1]) && ! ctype_digit($characters[$index])) { |
|
| 119 | 119 | $result[] = '0'; |
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | // Do some error checking. |
| 125 | - $count = count( $result ); |
|
| 126 | - $count_seg = mb_strlen( $this->get_segment( $pattern ) ); |
|
| 127 | - $sequence = implode( $result ); |
|
| 125 | + $count = count($result); |
|
| 126 | + $count_seg = mb_strlen($this->get_segment($pattern)); |
|
| 127 | + $sequence = implode($result); |
|
| 128 | 128 | |
| 129 | - if ( $count !== $count_seg + 1 ) { |
|
| 130 | - throw new \RangeException( "Invalid segment length $count for pattern $pattern (result sequence $sequence)." ); |
|
| 129 | + if ($count !== $count_seg + 1) { |
|
| 130 | + throw new \RangeException("Invalid segment length $count for pattern $pattern (result sequence $sequence)."); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | return $sequence; |
@@ -146,32 +146,32 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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,8 +267,8 @@ discard block |
||
| 267 | 267 | * @return string |
| 268 | 268 | */ |
| 269 | 269 | public function convert() { |
| 270 | - if ( ! file_exists( $this->url ) && 404 === File_Operations::get_http_response_code( $this->url ) ) { |
|
| 271 | - throw new \RuntimeException( "Error: unknown pattern file '{$this->url}'\n" ); |
|
| 270 | + if ( ! file_exists($this->url) && 404 === File_Operations::get_http_response_code($this->url)) { |
|
| 271 | + throw new \RuntimeException("Error: unknown pattern file '{$this->url}'\n"); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | // Results. |
@@ -280,36 +280,36 @@ discard block |
||
| 280 | 280 | $reading_patterns = false; |
| 281 | 281 | $reading_exceptions = false; |
| 282 | 282 | |
| 283 | - $file = new \SplFileObject( $this->url ); |
|
| 284 | - while ( ! $file->eof() ) { |
|
| 283 | + $file = new \SplFileObject($this->url); |
|
| 284 | + while ( ! $file->eof()) { |
|
| 285 | 285 | $line = $file->fgets(); |
| 286 | 286 | |
| 287 | - if ( $reading_patterns ) { |
|
| 288 | - $reading_patterns = $this->match_patterns( $line, $patterns ); |
|
| 289 | - } elseif ( $reading_exceptions ) { |
|
| 290 | - $reading_exceptions = $this->match_exceptions( $line, $exceptions ); |
|
| 287 | + if ($reading_patterns) { |
|
| 288 | + $reading_patterns = $this->match_patterns($line, $patterns); |
|
| 289 | + } elseif ($reading_exceptions) { |
|
| 290 | + $reading_exceptions = $this->match_exceptions($line, $exceptions); |
|
| 291 | 291 | } else { |
| 292 | 292 | // Not a pattern & not an exception. |
| 293 | - if ( preg_match( '/^\s*%.*$/u', $line, $matches ) ) { |
|
| 293 | + if (preg_match('/^\s*%.*$/u', $line, $matches)) { |
|
| 294 | 294 | $comments[] = $line; |
| 295 | - } elseif ( preg_match( '/^\s*\\\patterns\s*\{\s*(.*)$/u', $line, $matches ) ) { |
|
| 296 | - $reading_patterns = $this->match_patterns( $matches[1], $patterns ); |
|
| 297 | - } elseif ( preg_match( '/^\s*\\\hyphenation\s*{\s*(.*)$/u', $line, $matches ) ) { |
|
| 298 | - $reading_exceptions = $this->match_exceptions( $matches[1], $exceptions ); |
|
| 299 | - } elseif ( preg_match( '/^\s*\\\endinput.*$/u', $line, $matches ) ) { |
|
| 295 | + } elseif (preg_match('/^\s*\\\patterns\s*\{\s*(.*)$/u', $line, $matches)) { |
|
| 296 | + $reading_patterns = $this->match_patterns($matches[1], $patterns); |
|
| 297 | + } elseif (preg_match('/^\s*\\\hyphenation\s*{\s*(.*)$/u', $line, $matches)) { |
|
| 298 | + $reading_exceptions = $this->match_exceptions($matches[1], $exceptions); |
|
| 299 | + } elseif (preg_match('/^\s*\\\endinput.*$/u', $line, $matches)) { |
|
| 300 | 300 | // Ignore this line completely. |
| 301 | 301 | continue; |
| 302 | - } elseif ( preg_match( '/^\s*\\\[\w]+.*$/u', $line, $matches ) ) { |
|
| 302 | + } elseif (preg_match('/^\s*\\\[\w]+.*$/u', $line, $matches)) { |
|
| 303 | 303 | // Treat other commands as comments unless we are matching exceptions or patterns. |
| 304 | 304 | $comments[] = $line; |
| 305 | - } elseif ( preg_match( '/^\s*$/u', $line, $matches ) ) { |
|
| 305 | + } elseif (preg_match('/^\s*$/u', $line, $matches)) { |
|
| 306 | 306 | continue; // Do nothing. |
| 307 | 307 | } else { |
| 308 | - throw new \RangeException( "Error: unknown line $line\n" ); |
|
| 308 | + throw new \RangeException("Error: unknown line $line\n"); |
|
| 309 | 309 | } |
| 310 | 310 | } |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - return $this->format_results( $patterns, $exceptions, $comments ); |
|
| 313 | + return $this->format_results($patterns, $exceptions, $comments); |
|
| 314 | 314 | } |
| 315 | 315 | } |
@@ -31,19 +31,19 @@ discard block |
||
| 31 | 31 | /** |
| 32 | 32 | * Autoload parser classes |
| 33 | 33 | */ |
| 34 | -$autoload = dirname( dirname( __DIR__ ) ) . '/vendor/autoload.php'; |
|
| 35 | -if ( file_exists( $autoload ) ) { |
|
| 34 | +$autoload = dirname(dirname(__DIR__)) . '/vendor/autoload.php'; |
|
| 35 | +if (file_exists($autoload)) { |
|
| 36 | 36 | require_once $autoload; |
| 37 | 37 | } else { |
| 38 | 38 | // We are a dependency of another project. |
| 39 | - require_once dirname( dirname( dirname( dirname( __DIR__ ) ) ) ) . '/autoload.php'; |
|
| 39 | + require_once dirname(dirname(dirname(dirname(__DIR__)))) . '/autoload.php'; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | $source_file = 'https://data.iana.org/TLD/tlds-alpha-by-domain.txt'; |
| 43 | -$target_file = dirname( __DIR__ ) . '/IANA/tlds-alpha-by-domain.txt'; |
|
| 43 | +$target_file = dirname(__DIR__) . '/IANA/tlds-alpha-by-domain.txt'; |
|
| 44 | 44 | |
| 45 | -if ( ! file_exists( $source_file ) ) { |
|
| 46 | - if ( 404 === File_Operations::get_http_response_code( $source_file ) ) { |
|
| 45 | +if ( ! file_exists($source_file)) { |
|
| 46 | + if (404 === File_Operations::get_http_response_code($source_file)) { |
|
| 47 | 47 | echo "Error: unknown TLD file '{$source_file}'\n"; |
| 48 | 48 | die( -3 ); |
| 49 | 49 | } |
@@ -51,19 +51,19 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | try { |
| 53 | 53 | echo 'Trying to update IANA top-level domain list ...'; |
| 54 | - $domain_list = file_get_contents( $source_file ); |
|
| 54 | + $domain_list = file_get_contents($source_file); |
|
| 55 | 55 | |
| 56 | 56 | // Ensure directory exists. |
| 57 | - if ( ! is_dir( dirname( $target_file ) ) ) { |
|
| 58 | - mkdir( dirname( $target_file ), 0755, true ); |
|
| 57 | + if ( ! is_dir(dirname($target_file))) { |
|
| 58 | + mkdir(dirname($target_file), 0755, true); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - $file = new \SplFileObject( $target_file, 'w' ); |
|
| 62 | - if ( 0 === $file->fwrite( $domain_list ) ) { |
|
| 61 | + $file = new \SplFileObject($target_file, 'w'); |
|
| 62 | + if (0 === $file->fwrite($domain_list)) { |
|
| 63 | 63 | echo " error writing file\n"; |
| 64 | 64 | } else { |
| 65 | 65 | echo " done\n"; |
| 66 | 66 | } |
| 67 | -} catch ( \Exception $e ) { |
|
| 67 | +} catch (\Exception $e) { |
|
| 68 | 68 | echo " error\n"; |
| 69 | 69 | } |