We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -149,15 +149,15 @@ |
||
149 | 149 | * |
150 | 150 | * @return Quotes|null Returns null in case of an invalid $style parameter. |
151 | 151 | */ |
152 | - public static function get_styled_quotes( $style, Settings $settings ) { |
|
153 | - if ( isset( self::$styles[ $style ] ) ) { |
|
154 | - return new Simple_Quotes( self::$styles[ $style ][ self::_OPEN ], self::$styles[ $style ][ self::_CLOSE ] ); |
|
152 | + public static function get_styled_quotes($style, Settings $settings) { |
|
153 | + if (isset(self::$styles[$style])) { |
|
154 | + return new Simple_Quotes(self::$styles[$style][self::_OPEN], self::$styles[$style][self::_CLOSE]); |
|
155 | 155 | } |
156 | 156 | |
157 | - if ( self::DOUBLE_GUILLEMETS_FRENCH === $style ) { |
|
157 | + if (self::DOUBLE_GUILLEMETS_FRENCH === $style) { |
|
158 | 158 | $space = $settings->no_break_narrow_space(); |
159 | 159 | |
160 | - return new Simple_Quotes( U::GUILLEMET_OPEN . $space, $space . U::GUILLEMET_CLOSE ); |
|
160 | + return new Simple_Quotes(U::GUILLEMET_OPEN . $space, $space . U::GUILLEMET_CLOSE); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | return null; |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | * @param string|null $language Optional. Short-form language name. Default null. |
93 | 93 | * @param array $exceptions Optional. Custom hyphenation exceptions. Default empty array. |
94 | 94 | */ |
95 | - public function __construct( $language = null, array $exceptions = [] ) { |
|
95 | + public function __construct($language = null, array $exceptions = []) { |
|
96 | 96 | |
97 | - if ( ! empty( $language ) ) { |
|
98 | - $this->set_language( $language ); |
|
97 | + if ( ! empty($language)) { |
|
98 | + $this->set_language($language); |
|
99 | 99 | } |
100 | 100 | |
101 | - if ( ! empty( $exceptions ) ) { |
|
102 | - $this->set_custom_exceptions( $exceptions ); |
|
101 | + if ( ! empty($exceptions)) { |
|
102 | + $this->set_custom_exceptions($exceptions); |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
@@ -108,31 +108,31 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @param array $exceptions Optional. An array of words with all hyphenation points marked with a hard hyphen. Default empty array. |
110 | 110 | */ |
111 | - public function set_custom_exceptions( array $exceptions = [] ) { |
|
112 | - if ( empty( $exceptions ) && empty( $this->custom_exceptions ) ) { |
|
111 | + public function set_custom_exceptions(array $exceptions = []) { |
|
112 | + if (empty($exceptions) && empty($this->custom_exceptions)) { |
|
113 | 113 | return; // Nothing to do at all. |
114 | 114 | } |
115 | 115 | |
116 | 116 | // Calculate hash & check against previous exceptions. |
117 | - $new_hash = self::get_object_hash( $exceptions ); |
|
118 | - if ( $this->custom_exceptions_hash === $new_hash ) { |
|
117 | + $new_hash = self::get_object_hash($exceptions); |
|
118 | + if ($this->custom_exceptions_hash === $new_hash) { |
|
119 | 119 | return; // No need to update exceptions. |
120 | 120 | } |
121 | 121 | |
122 | 122 | // Do our thing. |
123 | 123 | $exception_keys = []; |
124 | - foreach ( $exceptions as $exception ) { |
|
125 | - $func = Strings::functions( $exception ); |
|
126 | - if ( empty( $func ) ) { |
|
124 | + foreach ($exceptions as $exception) { |
|
125 | + $func = Strings::functions($exception); |
|
126 | + if (empty($func)) { |
|
127 | 127 | continue; // unknown encoding, abort. |
128 | 128 | } |
129 | 129 | |
130 | - $exception = $func['strtolower']( $exception ); |
|
131 | - $exception_keys[ $exception ] = preg_replace( "#-#{$func['u']}", '', $exception ); |
|
130 | + $exception = $func['strtolower']($exception); |
|
131 | + $exception_keys[$exception] = preg_replace("#-#{$func['u']}", '', $exception); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | // Update exceptions. |
135 | - $this->custom_exceptions = array_flip( $exception_keys ); |
|
135 | + $this->custom_exceptions = array_flip($exception_keys); |
|
136 | 136 | $this->custom_exceptions_hash = $new_hash; |
137 | 137 | |
138 | 138 | // Force remerging of patgen and custom exception patterns. |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | * |
147 | 147 | * @return string |
148 | 148 | */ |
149 | - protected static function get_object_hash( $object ) { |
|
150 | - return md5( json_encode( $object ), false ); |
|
149 | + protected static function get_object_hash($object) { |
|
150 | + return md5(json_encode($object), false); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -157,23 +157,23 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @return bool Whether loading the pattern file was successful. |
159 | 159 | */ |
160 | - public function set_language( $lang = 'en-US' ) { |
|
161 | - if ( isset( $this->language ) && $this->language === $lang ) { |
|
160 | + public function set_language($lang = 'en-US') { |
|
161 | + if (isset($this->language) && $this->language === $lang) { |
|
162 | 162 | return true; // Bail out, no need to do anything. |
163 | 163 | } |
164 | 164 | |
165 | 165 | $success = false; |
166 | - $language_file_name = dirname( __FILE__ ) . '/lang/' . $lang . '.json'; |
|
166 | + $language_file_name = dirname(__FILE__) . '/lang/' . $lang . '.json'; |
|
167 | 167 | |
168 | - if ( file_exists( $language_file_name ) ) { |
|
169 | - $raw_language_file = file_get_contents( $language_file_name ); |
|
168 | + if (file_exists($language_file_name)) { |
|
169 | + $raw_language_file = file_get_contents($language_file_name); |
|
170 | 170 | |
171 | - if ( false !== $raw_language_file ) { |
|
172 | - $language_file = json_decode( $raw_language_file, true ); |
|
171 | + if (false !== $raw_language_file) { |
|
172 | + $language_file = json_decode($raw_language_file, true); |
|
173 | 173 | |
174 | - if ( false !== $language_file ) { |
|
174 | + if (false !== $language_file) { |
|
175 | 175 | $this->language = $lang; |
176 | - $this->pattern_trie = Trie_Node::build_trie( $language_file['patterns'] ); |
|
176 | + $this->pattern_trie = Trie_Node::build_trie($language_file['patterns']); |
|
177 | 177 | $this->pattern_exceptions = $language_file['exceptions']; |
178 | 178 | |
179 | 179 | $success = true; |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | } |
183 | 183 | |
184 | 184 | // Clean up. |
185 | - if ( ! $success ) { |
|
185 | + if ( ! $success) { |
|
186 | 186 | $this->language = null; |
187 | 187 | $this->pattern_trie = null; |
188 | 188 | $this->pattern_exceptions = []; |
@@ -206,18 +206,18 @@ discard block |
||
206 | 206 | * |
207 | 207 | * @return array The modified text tokens. |
208 | 208 | */ |
209 | - public function hyphenate( $parsed_text_tokens, $hyphen = '-', $hyphenate_title_case = false, $min_length = 2, $min_before = 2, $min_after = 2 ) { |
|
210 | - if ( empty( $min_length ) || empty( $min_before ) || ! isset( $this->pattern_trie ) || ! isset( $this->pattern_exceptions ) ) { |
|
209 | + public function hyphenate($parsed_text_tokens, $hyphen = '-', $hyphenate_title_case = false, $min_length = 2, $min_before = 2, $min_after = 2) { |
|
210 | + if (empty($min_length) || empty($min_before) || ! isset($this->pattern_trie) || ! isset($this->pattern_exceptions)) { |
|
211 | 211 | return $parsed_text_tokens; |
212 | 212 | } |
213 | 213 | |
214 | 214 | // Make sure we have full exceptions list. |
215 | - if ( ! isset( $this->merged_exception_patterns ) ) { |
|
215 | + if ( ! isset($this->merged_exception_patterns)) { |
|
216 | 216 | $this->merge_hyphenation_exceptions(); |
217 | 217 | } |
218 | 218 | |
219 | - foreach ( $parsed_text_tokens as $key => $text_token ) { |
|
220 | - $parsed_text_tokens[ $key ] = $text_token->with_value( $this->hyphenate_word( $text_token->value, $hyphen, $hyphenate_title_case, $min_length, $min_before, $min_after ) ); |
|
219 | + foreach ($parsed_text_tokens as $key => $text_token) { |
|
220 | + $parsed_text_tokens[$key] = $text_token->with_value($this->hyphenate_word($text_token->value, $hyphen, $hyphenate_title_case, $min_length, $min_before, $min_after)); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | return $parsed_text_tokens; |
@@ -235,48 +235,48 @@ discard block |
||
235 | 235 | * |
236 | 236 | * @return string |
237 | 237 | */ |
238 | - protected function hyphenate_word( $word, $hyphen, $hyphenate_title_case, $min_length, $min_before, $min_after ) { |
|
238 | + protected function hyphenate_word($word, $hyphen, $hyphenate_title_case, $min_length, $min_before, $min_after) { |
|
239 | 239 | // Quickly reference string functions according to encoding. |
240 | - $func = Strings::functions( $word ); |
|
241 | - if ( empty( $func ) ) { |
|
240 | + $func = Strings::functions($word); |
|
241 | + if (empty($func)) { |
|
242 | 242 | return $word; // unknown encoding, abort. |
243 | 243 | } |
244 | 244 | |
245 | 245 | // Check word length. |
246 | - $word_length = $func['strlen']( $word ); |
|
247 | - if ( $word_length < $min_length ) { |
|
246 | + $word_length = $func['strlen']($word); |
|
247 | + if ($word_length < $min_length) { |
|
248 | 248 | return $word; |
249 | 249 | } |
250 | 250 | |
251 | 251 | // Trie lookup requires a lowercase search term. |
252 | - $the_key = $func['strtolower']( $word ); |
|
252 | + $the_key = $func['strtolower']($word); |
|
253 | 253 | |
254 | 254 | // If this is a capitalized word, and settings do not allow hyphenation of such, abort! |
255 | 255 | // Note: This is different than uppercase words, where we are looking for title case. |
256 | - if ( ! $hyphenate_title_case && $func['substr']( $the_key, 0, 1 ) !== $func['substr']( $word, 0, 1 ) ) { |
|
256 | + if ( ! $hyphenate_title_case && $func['substr']($the_key, 0, 1) !== $func['substr']($word, 0, 1)) { |
|
257 | 257 | return $word; |
258 | 258 | } |
259 | 259 | |
260 | 260 | // Give exceptions preference. |
261 | - if ( isset( $this->merged_exception_patterns[ $the_key ] ) ) { |
|
262 | - $word_pattern = $this->merged_exception_patterns[ $the_key ]; |
|
261 | + if (isset($this->merged_exception_patterns[$the_key])) { |
|
262 | + $word_pattern = $this->merged_exception_patterns[$the_key]; |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | // Lookup word pattern if there is no exception. |
266 | - if ( ! isset( $word_pattern ) ) { |
|
267 | - $word_pattern = $this->lookup_word_pattern( $the_key, $func['strlen'], $func['str_split'] ); |
|
266 | + if ( ! isset($word_pattern)) { |
|
267 | + $word_pattern = $this->lookup_word_pattern($the_key, $func['strlen'], $func['str_split']); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | // Add hyphen character based on $word_pattern. |
271 | - $word_parts = $func['str_split']( $word, 1 ); |
|
271 | + $word_parts = $func['str_split']($word, 1); |
|
272 | 272 | $hyphenated_word = ''; |
273 | 273 | |
274 | - for ( $i = 0; $i < $word_length; $i++ ) { |
|
275 | - if ( isset( $word_pattern[ $i ] ) && self::is_odd( $word_pattern[ $i ] ) && ( $i >= $min_before) && ( $i <= $word_length - $min_after ) ) { |
|
274 | + for ($i = 0; $i < $word_length; $i++) { |
|
275 | + if (isset($word_pattern[$i]) && self::is_odd($word_pattern[$i]) && ($i >= $min_before) && ($i <= $word_length - $min_after)) { |
|
276 | 276 | $hyphenated_word .= $hyphen; |
277 | 277 | } |
278 | 278 | |
279 | - $hyphenated_word .= $word_parts[ $i ]; |
|
279 | + $hyphenated_word .= $word_parts[$i]; |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | return $hyphenated_word; |
@@ -291,33 +291,33 @@ discard block |
||
291 | 291 | * |
292 | 292 | * @return array The hyphenation pattern. |
293 | 293 | */ |
294 | - protected function lookup_word_pattern( $key, callable $strlen, callable $str_split ) { |
|
294 | + protected function lookup_word_pattern($key, callable $strlen, callable $str_split) { |
|
295 | 295 | // Add underscores to make out-of-index checks unnecessary, |
296 | 296 | // also hyphenation is done in lower case. |
297 | 297 | $search = '_' . $key . '_'; |
298 | - $search_length = $strlen( $search ); |
|
299 | - $chars = $str_split( $search ); |
|
298 | + $search_length = $strlen($search); |
|
299 | + $chars = $str_split($search); |
|
300 | 300 | $word_pattern = []; |
301 | 301 | |
302 | - for ( $start = 0; $start < $search_length; ++$start ) { |
|
302 | + for ($start = 0; $start < $search_length; ++$start) { |
|
303 | 303 | // Start from the trie root node. |
304 | 304 | $node = $this->pattern_trie; |
305 | 305 | |
306 | 306 | // Walk through the trie while storing detected patterns. |
307 | - for ( $step = $start; $step < $search_length; ++$step ) { |
|
307 | + for ($step = $start; $step < $search_length; ++$step) { |
|
308 | 308 | // No further path in the trie. |
309 | - if ( ! $node->exists( $chars[ $step ] ) ) { |
|
309 | + if ( ! $node->exists($chars[$step])) { |
|
310 | 310 | break; |
311 | 311 | } |
312 | 312 | |
313 | 313 | // Look for next character. |
314 | - $node = $node->get_node( $chars[ $step ] ); |
|
314 | + $node = $node->get_node($chars[$step]); |
|
315 | 315 | |
316 | 316 | // Merge different offset values and keep maximum. |
317 | - foreach ( $node->offsets() as $pattern_offset ) { |
|
317 | + foreach ($node->offsets() as $pattern_offset) { |
|
318 | 318 | $value = $pattern_offset[0]; |
319 | 319 | $offset = $pattern_offset[1] + $start - 1; |
320 | - $word_pattern[ $offset ] = isset( $word_pattern[ $offset ] ) ? max( $word_pattern[ $offset ], $value ) : $value; |
|
320 | + $word_pattern[$offset] = isset($word_pattern[$offset]) ? max($word_pattern[$offset], $value) : $value; |
|
321 | 321 | } |
322 | 322 | } |
323 | 323 | } |
@@ -333,18 +333,18 @@ discard block |
||
333 | 333 | $exceptions = []; |
334 | 334 | |
335 | 335 | // Merge custom and language specific word hyphenations. |
336 | - if ( ! empty( $this->pattern_exceptions ) && ! empty( $this->custom_exceptions ) ) { |
|
337 | - $exceptions = array_merge( $this->custom_exceptions, $this->pattern_exceptions ); |
|
338 | - } elseif ( ! empty( $this->pattern_exceptions ) ) { |
|
336 | + if ( ! empty($this->pattern_exceptions) && ! empty($this->custom_exceptions)) { |
|
337 | + $exceptions = array_merge($this->custom_exceptions, $this->pattern_exceptions); |
|
338 | + } elseif ( ! empty($this->pattern_exceptions)) { |
|
339 | 339 | $exceptions = $this->pattern_exceptions; |
340 | - } elseif ( ! empty( $this->custom_exceptions ) ) { |
|
340 | + } elseif ( ! empty($this->custom_exceptions)) { |
|
341 | 341 | $exceptions = $this->custom_exceptions; |
342 | 342 | } |
343 | 343 | |
344 | 344 | // Update patterns as well. |
345 | 345 | $exception_patterns = []; |
346 | - foreach ( $exceptions as $exception_key => $exception ) { |
|
347 | - $exception_patterns[ $exception_key ] = self::convert_hyphenation_exception_to_pattern( $exception ); |
|
346 | + foreach ($exceptions as $exception_key => $exception) { |
|
347 | + $exception_patterns[$exception_key] = self::convert_hyphenation_exception_to_pattern($exception); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | $this->merged_exception_patterns = $exception_patterns; |
@@ -357,22 +357,22 @@ discard block |
||
357 | 357 | * |
358 | 358 | * @return array|null Returns the hyphenation pattern or null if `$exception` is using an invalid encoding. |
359 | 359 | */ |
360 | - protected static function convert_hyphenation_exception_to_pattern( $exception ) { |
|
361 | - $func = Strings::functions( $exception ); |
|
362 | - if ( empty( $func ) ) { |
|
360 | + protected static function convert_hyphenation_exception_to_pattern($exception) { |
|
361 | + $func = Strings::functions($exception); |
|
362 | + if (empty($func)) { |
|
363 | 363 | return null; // unknown encoding, abort. |
364 | 364 | } |
365 | 365 | |
366 | 366 | // Set the word_pattern - this method keeps any contextually important capitalization. |
367 | - $lowercase_hyphened_word_parts = $func['str_split']( $exception, 1 ); |
|
368 | - $lowercase_hyphened_word_length = $func['strlen']( $exception ); |
|
367 | + $lowercase_hyphened_word_parts = $func['str_split']($exception, 1); |
|
368 | + $lowercase_hyphened_word_length = $func['strlen']($exception); |
|
369 | 369 | |
370 | 370 | $word_pattern = []; |
371 | 371 | $index = 0; |
372 | 372 | |
373 | - for ( $i = 0; $i < $lowercase_hyphened_word_length; $i++ ) { |
|
374 | - if ( '-' === $lowercase_hyphened_word_parts[ $i ] ) { |
|
375 | - $word_pattern[ $index ] = 9; |
|
373 | + for ($i = 0; $i < $lowercase_hyphened_word_length; $i++) { |
|
374 | + if ('-' === $lowercase_hyphened_word_parts[$i]) { |
|
375 | + $word_pattern[$index] = 9; |
|
376 | 376 | } else { |
377 | 377 | $index++; |
378 | 378 | } |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | * |
389 | 389 | * @return bool true if $number is odd, false if it is even. |
390 | 390 | */ |
391 | - protected static function is_odd( $number ) { |
|
392 | - return (bool) ( $number % 2 ); |
|
391 | + protected static function is_odd($number) { |
|
392 | + return (bool) ($number % 2); |
|
393 | 393 | } |
394 | 394 | } |
@@ -46,7 +46,7 @@ |
||
46 | 46 | * |
47 | 47 | * @return void |
48 | 48 | */ |
49 | - public function apply( \DOMText $textnode, Settings $settings, $is_title = false ); |
|
49 | + public function apply(\DOMText $textnode, Settings $settings, $is_title = false); |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Determines whether the fix should be applied to (RSS) feeds. |
@@ -52,7 +52,7 @@ |
||
52 | 52 | * |
53 | 53 | * @return array An array of tokens. |
54 | 54 | */ |
55 | - public function apply( array $tokens, Settings $settings, $is_title = false, \DOMText $textnode = null ); |
|
55 | + public function apply(array $tokens, Settings $settings, $is_title = false, \DOMText $textnode = null); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Determines whether the fix should be applied to (RSS) feeds. |
@@ -80,7 +80,7 @@ |
||
80 | 80 | * |
81 | 81 | * @param bool $feed_compatible Optional. Default false. |
82 | 82 | */ |
83 | - public function __construct( $feed_compatible = false ) { |
|
84 | - parent::__construct( self::REGEX, self::REPLACEMENT, self::SETTING, $feed_compatible ); |
|
83 | + public function __construct($feed_compatible = false) { |
|
84 | + parent::__construct(self::REGEX, self::REPLACEMENT, self::SETTING, $feed_compatible); |
|
85 | 85 | } |
86 | 86 | } |
@@ -56,25 +56,25 @@ |
||
56 | 56 | * @param Settings $settings Required. |
57 | 57 | * @param bool $is_title Optional. Default false. |
58 | 58 | */ |
59 | - public function apply( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
60 | - if ( empty( $settings['singleCharacterWordSpacing'] ) ) { |
|
59 | + public function apply(\DOMText $textnode, Settings $settings, $is_title = false) { |
|
60 | + if (empty($settings['singleCharacterWordSpacing'])) { |
|
61 | 61 | return; |
62 | 62 | } |
63 | 63 | |
64 | 64 | // Add $next_character and $previous_character for context. |
65 | - $previous_character = DOM::get_prev_chr( $textnode ); |
|
66 | - if ( '' !== $previous_character ) { |
|
65 | + $previous_character = DOM::get_prev_chr($textnode); |
|
66 | + if ('' !== $previous_character) { |
|
67 | 67 | $textnode->data = $previous_character . $textnode->data; |
68 | 68 | } |
69 | 69 | |
70 | - $next_character = DOM::get_next_chr( $textnode ); |
|
71 | - if ( '' !== $next_character ) { |
|
70 | + $next_character = DOM::get_next_chr($textnode); |
|
71 | + if ('' !== $next_character) { |
|
72 | 72 | $textnode->data = $textnode->data . $next_character; |
73 | 73 | } |
74 | 74 | |
75 | - $textnode->data = preg_replace( self::REGEX, '$1$2' . U::NO_BREAK_SPACE, $textnode->data ); |
|
75 | + $textnode->data = preg_replace(self::REGEX, '$1$2' . U::NO_BREAK_SPACE, $textnode->data); |
|
76 | 76 | |
77 | 77 | // If we have adjacent characters remove them from the text. |
78 | - $textnode->data = self::remove_adjacent_characters( $textnode->data, $previous_character, $next_character ); |
|
78 | + $textnode->data = self::remove_adjacent_characters($textnode->data, $previous_character, $next_character); |
|
79 | 79 | } |
80 | 80 | } |
@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | * @param array|string $classes HTML class(es). |
52 | 52 | * @param bool $feed_compatible Optional. Default false. |
53 | 53 | */ |
54 | - public function __construct( $classes, $feed_compatible = false ) { |
|
55 | - parent::__construct( $feed_compatible ); |
|
54 | + public function __construct($classes, $feed_compatible = false) { |
|
55 | + parent::__construct($feed_compatible); |
|
56 | 56 | |
57 | - if ( ! is_array( $classes ) ) { |
|
58 | - $classes = [ $classes ]; |
|
57 | + if ( ! is_array($classes)) { |
|
58 | + $classes = [$classes]; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | $this->classes_to_avoid = $classes; |
@@ -70,9 +70,9 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return void |
72 | 72 | */ |
73 | - public function apply( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
74 | - if ( ! DOM::has_class( $textnode, $this->classes_to_avoid ) ) { |
|
75 | - $this->apply_internal( $textnode, $settings, $is_title ); |
|
73 | + public function apply(\DOMText $textnode, Settings $settings, $is_title = false) { |
|
74 | + if ( ! DOM::has_class($textnode, $this->classes_to_avoid)) { |
|
75 | + $this->apply_internal($textnode, $settings, $is_title); |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 | |
@@ -85,5 +85,5 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @return void |
87 | 87 | */ |
88 | - abstract public function apply_internal( \DOMText $textnode, Settings $settings, $is_title = false ); |
|
88 | + abstract public function apply_internal(\DOMText $textnode, Settings $settings, $is_title = false); |
|
89 | 89 | } |
@@ -104,19 +104,19 @@ discard block |
||
104 | 104 | * @param string $css_denominator CSS class applied to the denominator part. |
105 | 105 | * @param bool $feed_compatible Optional. Default false. |
106 | 106 | */ |
107 | - public function __construct( $css_numerator, $css_denominator, $feed_compatible = false ) { |
|
108 | - parent::__construct( $feed_compatible ); |
|
107 | + public function __construct($css_numerator, $css_denominator, $feed_compatible = false) { |
|
108 | + parent::__construct($feed_compatible); |
|
109 | 109 | |
110 | 110 | // Escape consecutive years. |
111 | 111 | $year_regex = []; |
112 | - for ( $year = 1900; $year < 2100; ++$year ) { |
|
113 | - $year_regex[] = "(?: ( $year ) (\s?\/\s?" . U::ZERO_WIDTH_SPACE . '?) ( ' . ( $year + 1 ) . ' ) )'; |
|
112 | + for ($year = 1900; $year < 2100; ++$year) { |
|
113 | + $year_regex[] = "(?: ( $year ) (\s?\/\s?" . U::ZERO_WIDTH_SPACE . '?) ( ' . ($year + 1) . ' ) )'; |
|
114 | 114 | } |
115 | 115 | $this->escape_consecutive_years = '/ |
116 | 116 | # lookbehind assertion: makes sure we are not messing up a url |
117 | 117 | (?<=\A|\s|' . U::NO_BREAK_SPACE . '|' . U::NO_BREAK_NARROW_SPACE . ') |
118 | 118 | |
119 | - (?| ' . implode( '|', $year_regex ) . ' ) |
|
119 | + (?| ' . implode('|', $year_regex) . ' ) |
|
120 | 120 | ( |
121 | 121 | # makes sure we are not messing up a url |
122 | 122 | (?:\Z|\s|' . U::NO_BREAK_SPACE . '|' . U::NO_BREAK_NARROW_SPACE . '|\.|\!|\?|\)|\;|\:|\'|\") |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | /xu'; |
125 | 125 | |
126 | 126 | // Replace fractions. |
127 | - $numerator_css = empty( $css_numerator ) ? '' : ' class="' . $css_numerator . '"'; |
|
128 | - $denominator_css = empty( $css_denominator ) ? '' : ' class="' . $css_denominator . '"'; |
|
127 | + $numerator_css = empty($css_numerator) ? '' : ' class="' . $css_numerator . '"'; |
|
128 | + $denominator_css = empty($css_denominator) ? '' : ' class="' . $css_denominator . '"'; |
|
129 | 129 | $this->replacement = "<sup{$numerator_css}>\$1</sup>" . U::FRACTION_SLASH . "<sub{$denominator_css}>\$2</sub>\$3"; |
130 | 130 | } |
131 | 131 | |
@@ -136,27 +136,27 @@ discard block |
||
136 | 136 | * @param Settings $settings Required. |
137 | 137 | * @param bool $is_title Optional. Default false. |
138 | 138 | */ |
139 | - public function apply( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
140 | - if ( empty( $settings['smartFractions'] ) && empty( $settings['fractionSpacing'] ) ) { |
|
139 | + public function apply(\DOMText $textnode, Settings $settings, $is_title = false) { |
|
140 | + if (empty($settings['smartFractions']) && empty($settings['fractionSpacing'])) { |
|
141 | 141 | return; |
142 | 142 | } |
143 | 143 | |
144 | - if ( ! empty( $settings['fractionSpacing'] ) && ! empty( $settings['smartFractions'] ) ) { |
|
145 | - $textnode->data = preg_replace( self::SPACING, '$1' . $settings->no_break_narrow_space() . '$2', $textnode->data ); |
|
146 | - } elseif ( ! empty( $settings['fractionSpacing'] ) && empty( $settings['smartFractions'] ) ) { |
|
147 | - $textnode->data = preg_replace( self::SPACING, '$1' . U::NO_BREAK_SPACE . '$2', $textnode->data ); |
|
144 | + if ( ! empty($settings['fractionSpacing']) && ! empty($settings['smartFractions'])) { |
|
145 | + $textnode->data = preg_replace(self::SPACING, '$1' . $settings->no_break_narrow_space() . '$2', $textnode->data); |
|
146 | + } elseif ( ! empty($settings['fractionSpacing']) && empty($settings['smartFractions'])) { |
|
147 | + $textnode->data = preg_replace(self::SPACING, '$1' . U::NO_BREAK_SPACE . '$2', $textnode->data); |
|
148 | 148 | } |
149 | 149 | |
150 | - if ( ! empty( $settings['smartFractions'] ) ) { |
|
150 | + if ( ! empty($settings['smartFractions'])) { |
|
151 | 151 | // Escape sequences we don't want fractionified. |
152 | - $textnode->data = preg_replace( $this->escape_consecutive_years, '$1' . RE::ESCAPE_MARKER . '$2$3$4', $textnode->data ); |
|
153 | - $textnode->data = preg_replace( self::ESCAPE_DATE_MM_YYYY, '$1' . RE::ESCAPE_MARKER . '$2$3$4', $textnode->data ); |
|
152 | + $textnode->data = preg_replace($this->escape_consecutive_years, '$1' . RE::ESCAPE_MARKER . '$2$3$4', $textnode->data); |
|
153 | + $textnode->data = preg_replace(self::ESCAPE_DATE_MM_YYYY, '$1' . RE::ESCAPE_MARKER . '$2$3$4', $textnode->data); |
|
154 | 154 | |
155 | 155 | // Replace fractions. |
156 | - $textnode->data = preg_replace( self::FRACTION_MATCHING, $this->replacement, $textnode->data ); |
|
156 | + $textnode->data = preg_replace(self::FRACTION_MATCHING, $this->replacement, $textnode->data); |
|
157 | 157 | |
158 | 158 | // Unescape escaped sequences. |
159 | - $textnode->data = str_replace( RE::ESCAPE_MARKER, '', $textnode->data ); |
|
159 | + $textnode->data = str_replace(RE::ESCAPE_MARKER, '', $textnode->data); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | } |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | * @param string $css_double Required. |
62 | 62 | * @param bool $feed_compatible Optional. Default false. |
63 | 63 | */ |
64 | - public function __construct( $css_single, $css_double, $feed_compatible = false ) { |
|
65 | - parent::__construct( [ $css_single, $css_double ], $feed_compatible ); |
|
64 | + public function __construct($css_single, $css_double, $feed_compatible = false) { |
|
65 | + parent::__construct([$css_single, $css_double], $feed_compatible); |
|
66 | 66 | |
67 | 67 | $this->single_quote_class = $css_single; |
68 | 68 | $this->double_quote_class = $css_double; |
@@ -75,32 +75,32 @@ discard block |
||
75 | 75 | * @param Settings $settings Required. |
76 | 76 | * @param bool $is_title Optional. Default false. |
77 | 77 | */ |
78 | - public function apply_internal( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
79 | - if ( empty( $settings['styleInitialQuotes'] ) || empty( $settings['initialQuoteTags'] ) ) { |
|
78 | + public function apply_internal(\DOMText $textnode, Settings $settings, $is_title = false) { |
|
79 | + if (empty($settings['styleInitialQuotes']) || empty($settings['initialQuoteTags'])) { |
|
80 | 80 | return; |
81 | 81 | } |
82 | 82 | |
83 | - if ( '' === DOM::get_prev_chr( $textnode ) ) { // we have the first text in a block level element. |
|
83 | + if ('' === DOM::get_prev_chr($textnode)) { // we have the first text in a block level element. |
|
84 | 84 | |
85 | - $func = Strings::functions( $textnode->data ); |
|
86 | - $first_character = $func['substr']( $textnode->data, 0, 1 ); |
|
85 | + $func = Strings::functions($textnode->data); |
|
86 | + $first_character = $func['substr']($textnode->data, 0, 1); |
|
87 | 87 | |
88 | - if ( self::is_single_quote( $first_character ) || self::is_double_quote( $first_character ) ) { |
|
89 | - $block_level_parent = DOM::get_block_parent_name( $textnode ); |
|
88 | + if (self::is_single_quote($first_character) || self::is_double_quote($first_character)) { |
|
89 | + $block_level_parent = DOM::get_block_parent_name($textnode); |
|
90 | 90 | |
91 | - if ( $is_title ) { |
|
91 | + if ($is_title) { |
|
92 | 92 | // Assume page title is h2. |
93 | 93 | $block_level_parent = 'h2'; |
94 | 94 | } |
95 | 95 | |
96 | - if ( ! empty( $block_level_parent ) && isset( $settings['initialQuoteTags'][ $block_level_parent ] ) ) { |
|
97 | - if ( self::is_single_quote( $first_character ) ) { |
|
96 | + if ( ! empty($block_level_parent) && isset($settings['initialQuoteTags'][$block_level_parent])) { |
|
97 | + if (self::is_single_quote($first_character)) { |
|
98 | 98 | $span_class = $this->single_quote_class; |
99 | 99 | } else { |
100 | 100 | $span_class = $this->double_quote_class; |
101 | 101 | } |
102 | 102 | |
103 | - $textnode->data = '<span class="' . $span_class . '">' . $first_character . '</span>' . $func['substr']( $textnode->data, 1, $func['strlen']( $textnode->data ) ); |
|
103 | + $textnode->data = '<span class="' . $span_class . '">' . $first_character . '</span>' . $func['substr']($textnode->data, 1, $func['strlen']($textnode->data)); |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | } |
@@ -113,8 +113,8 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @return bool |
115 | 115 | */ |
116 | - private static function is_single_quote( $quote ) { |
|
117 | - return ( "'" === $quote || U::SINGLE_QUOTE_OPEN === $quote || U::SINGLE_LOW_9_QUOTE === $quote || U::SINGLE_ANGLE_QUOTE_OPEN === $quote || U::SINGLE_ANGLE_QUOTE_CLOSE === $quote || ',' === $quote ); |
|
116 | + private static function is_single_quote($quote) { |
|
117 | + return ("'" === $quote || U::SINGLE_QUOTE_OPEN === $quote || U::SINGLE_LOW_9_QUOTE === $quote || U::SINGLE_ANGLE_QUOTE_OPEN === $quote || U::SINGLE_ANGLE_QUOTE_CLOSE === $quote || ',' === $quote); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * |
125 | 125 | * @return bool |
126 | 126 | */ |
127 | - private static function is_double_quote( $quote ) { |
|
128 | - return ( '"' === $quote || U::DOUBLE_QUOTE_OPEN === $quote || U::GUILLEMET_OPEN === $quote || U::GUILLEMET_CLOSE === $quote || U::DOUBLE_LOW_9_QUOTE === $quote ); |
|
127 | + private static function is_double_quote($quote) { |
|
128 | + return ('"' === $quote || U::DOUBLE_QUOTE_OPEN === $quote || U::GUILLEMET_OPEN === $quote || U::GUILLEMET_CLOSE === $quote || U::DOUBLE_LOW_9_QUOTE === $quote); |
|
129 | 129 | } |
130 | 130 | } |