We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -126,11 +126,11 @@ discard block |
||
126 | 126 | * |
127 | 127 | * @param bool $feed_compatible Optional. Default false. |
128 | 128 | */ |
129 | - public function __construct( $feed_compatible = false ) { |
|
130 | - parent::__construct( $feed_compatible ); |
|
129 | + public function __construct($feed_compatible = false) { |
|
130 | + parent::__construct($feed_compatible); |
|
131 | 131 | |
132 | - $this->apostrophe_exception_matches = array_keys( self::APOSTROPHE_EXCEPTIONS ); |
|
133 | - $this->apostrophe_exception_replacements = array_values( self::APOSTROPHE_EXCEPTIONS ); |
|
132 | + $this->apostrophe_exception_matches = array_keys(self::APOSTROPHE_EXCEPTIONS); |
|
133 | + $this->apostrophe_exception_replacements = array_values(self::APOSTROPHE_EXCEPTIONS); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -140,19 +140,19 @@ discard block |
||
140 | 140 | * @param Settings $settings Required. |
141 | 141 | * @param bool $is_title Optional. Default false. |
142 | 142 | */ |
143 | - public function apply( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
144 | - if ( empty( $settings['smartQuotes'] ) ) { |
|
143 | + public function apply(\DOMText $textnode, Settings $settings, $is_title = false) { |
|
144 | + if (empty($settings['smartQuotes'])) { |
|
145 | 145 | return; |
146 | 146 | } |
147 | 147 | |
148 | 148 | // Need to get context of adjacent characters outside adjacent inline tags or HTML comment |
149 | 149 | // if we have adjacent characters add them to the text. |
150 | - $previous_character = DOM::get_prev_chr( $textnode ); |
|
151 | - if ( '' !== $previous_character ) { |
|
150 | + $previous_character = DOM::get_prev_chr($textnode); |
|
151 | + if ('' !== $previous_character) { |
|
152 | 152 | $textnode->data = $previous_character . $textnode->data; |
153 | 153 | } |
154 | - $next_character = DOM::get_next_chr( $textnode ); |
|
155 | - if ( '' !== $next_character ) { |
|
154 | + $next_character = DOM::get_next_chr($textnode); |
|
155 | + if ('' !== $next_character) { |
|
156 | 156 | $textnode->data = $textnode->data . $next_character; |
157 | 157 | } |
158 | 158 | |
@@ -165,63 +165,63 @@ discard block |
||
165 | 165 | $single_open = $single->open(); |
166 | 166 | $single_close = $single->close(); |
167 | 167 | |
168 | - if ( $double != $this->cached_primary_quotes || $single != $this->cached_secondary_quotes ) { |
|
169 | - $this->update_smart_quotes_brackets( $double_open, $double_close, $single_open, $single_close ); |
|
168 | + if ($double != $this->cached_primary_quotes || $single != $this->cached_secondary_quotes) { |
|
169 | + $this->update_smart_quotes_brackets($double_open, $double_close, $single_open, $single_close); |
|
170 | 170 | $this->cached_primary_quotes = $double; |
171 | 171 | $this->cached_secondary_quotes = $single; |
172 | 172 | } |
173 | 173 | |
174 | 174 | // Before primes, handle quoted numbers (and quotes ending in numbers). |
175 | - $textnode->data = preg_replace( self::SINGLE_QUOTED_NUMBERS, "{$single_open}\$1{$single_close}", $textnode->data ); |
|
176 | - $textnode->data = preg_replace( self::DOUBLE_QUOTED_NUMBERS, "{$double_open}\$1{$double_close}", $textnode->data ); |
|
175 | + $textnode->data = preg_replace(self::SINGLE_QUOTED_NUMBERS, "{$single_open}\$1{$single_close}", $textnode->data); |
|
176 | + $textnode->data = preg_replace(self::DOUBLE_QUOTED_NUMBERS, "{$double_open}\$1{$double_close}", $textnode->data); |
|
177 | 177 | |
178 | 178 | // Guillemets. |
179 | - $textnode->data = str_replace( '<<', U::GUILLEMET_OPEN, $textnode->data ); |
|
180 | - $textnode->data = str_replace( '<<', U::GUILLEMET_OPEN, $textnode->data ); |
|
181 | - $textnode->data = str_replace( '>>', U::GUILLEMET_CLOSE, $textnode->data ); |
|
182 | - $textnode->data = str_replace( '>>', U::GUILLEMET_CLOSE, $textnode->data ); |
|
179 | + $textnode->data = str_replace('<<', U::GUILLEMET_OPEN, $textnode->data); |
|
180 | + $textnode->data = str_replace('<<', U::GUILLEMET_OPEN, $textnode->data); |
|
181 | + $textnode->data = str_replace('>>', U::GUILLEMET_CLOSE, $textnode->data); |
|
182 | + $textnode->data = str_replace('>>', U::GUILLEMET_CLOSE, $textnode->data); |
|
183 | 183 | |
184 | 184 | // Primes. |
185 | - $textnode->data = preg_replace( self::SINGLE_DOUBLE_PRIME, '$1' . U::SINGLE_PRIME . '$2$3' . U::DOUBLE_PRIME, $textnode->data ); |
|
186 | - $textnode->data = preg_replace( self::SINGLE_DOUBLE_PRIME_1_GLYPH, '$1' . U::SINGLE_PRIME . '$2$3' . U::DOUBLE_PRIME, $textnode->data ); |
|
187 | - $textnode->data = preg_replace( self::DOUBLE_PRIME, '$1' . U::DOUBLE_PRIME, $textnode->data ); // should not interfere with regular quote matching. |
|
188 | - $textnode->data = preg_replace( self::SINGLE_PRIME, '$1' . U::SINGLE_PRIME, $textnode->data ); |
|
189 | - $textnode->data = preg_replace( self::SINGLE_PRIME_COMPOUND, '$1' . U::SINGLE_PRIME, $textnode->data ); |
|
190 | - $textnode->data = preg_replace( self::DOUBLE_PRIME_COMPOUND, '$1' . U::DOUBLE_PRIME, $textnode->data ); |
|
191 | - $textnode->data = preg_replace( self::DOUBLE_PRIME_1_GLYPH, '$1' . U::DOUBLE_PRIME, $textnode->data ); // should not interfere with regular quote matching. |
|
192 | - $textnode->data = preg_replace( self::DOUBLE_PRIME_1_GLYPH_COMPOUND, '$1' . U::DOUBLE_PRIME, $textnode->data ); |
|
185 | + $textnode->data = preg_replace(self::SINGLE_DOUBLE_PRIME, '$1' . U::SINGLE_PRIME . '$2$3' . U::DOUBLE_PRIME, $textnode->data); |
|
186 | + $textnode->data = preg_replace(self::SINGLE_DOUBLE_PRIME_1_GLYPH, '$1' . U::SINGLE_PRIME . '$2$3' . U::DOUBLE_PRIME, $textnode->data); |
|
187 | + $textnode->data = preg_replace(self::DOUBLE_PRIME, '$1' . U::DOUBLE_PRIME, $textnode->data); // should not interfere with regular quote matching. |
|
188 | + $textnode->data = preg_replace(self::SINGLE_PRIME, '$1' . U::SINGLE_PRIME, $textnode->data); |
|
189 | + $textnode->data = preg_replace(self::SINGLE_PRIME_COMPOUND, '$1' . U::SINGLE_PRIME, $textnode->data); |
|
190 | + $textnode->data = preg_replace(self::DOUBLE_PRIME_COMPOUND, '$1' . U::DOUBLE_PRIME, $textnode->data); |
|
191 | + $textnode->data = preg_replace(self::DOUBLE_PRIME_1_GLYPH, '$1' . U::DOUBLE_PRIME, $textnode->data); // should not interfere with regular quote matching. |
|
192 | + $textnode->data = preg_replace(self::DOUBLE_PRIME_1_GLYPH_COMPOUND, '$1' . U::DOUBLE_PRIME, $textnode->data); |
|
193 | 193 | |
194 | 194 | // Backticks. |
195 | - $textnode->data = str_replace( '``', $double_open, $textnode->data ); |
|
196 | - $textnode->data = str_replace( '`', $single_open, $textnode->data ); |
|
197 | - $textnode->data = str_replace( "''", $double_close, $textnode->data ); |
|
195 | + $textnode->data = str_replace('``', $double_open, $textnode->data); |
|
196 | + $textnode->data = str_replace('`', $single_open, $textnode->data); |
|
197 | + $textnode->data = str_replace("''", $double_close, $textnode->data); |
|
198 | 198 | |
199 | 199 | // Comma quotes. |
200 | - $textnode->data = str_replace( ',,', U::DOUBLE_LOW_9_QUOTE, $textnode->data ); |
|
201 | - $textnode->data = preg_replace( self::COMMA_QUOTE, U::SINGLE_LOW_9_QUOTE, $textnode->data ); // like _,¿hola?'_. |
|
200 | + $textnode->data = str_replace(',,', U::DOUBLE_LOW_9_QUOTE, $textnode->data); |
|
201 | + $textnode->data = preg_replace(self::COMMA_QUOTE, U::SINGLE_LOW_9_QUOTE, $textnode->data); // like _,¿hola?'_. |
|
202 | 202 | |
203 | 203 | // Apostrophes. |
204 | - $textnode->data = preg_replace( self::APOSTROPHE_WORDS, U::APOSTROPHE, $textnode->data ); |
|
205 | - $textnode->data = preg_replace( self::APOSTROPHE_DECADES, U::APOSTROPHE . '$1', $textnode->data ); // decades: '98. |
|
206 | - $textnode->data = str_replace( $this->apostrophe_exception_matches, $this->apostrophe_exception_replacements, $textnode->data ); |
|
204 | + $textnode->data = preg_replace(self::APOSTROPHE_WORDS, U::APOSTROPHE, $textnode->data); |
|
205 | + $textnode->data = preg_replace(self::APOSTROPHE_DECADES, U::APOSTROPHE . '$1', $textnode->data); // decades: '98. |
|
206 | + $textnode->data = str_replace($this->apostrophe_exception_matches, $this->apostrophe_exception_replacements, $textnode->data); |
|
207 | 207 | |
208 | 208 | // Quotes. |
209 | - $textnode->data = str_replace( $this->brackets_matches, $this->brackets_replacements, $textnode->data ); |
|
210 | - $textnode->data = preg_replace( self::SINGLE_QUOTE_OPEN, $single_open, $textnode->data ); |
|
211 | - $textnode->data = preg_replace( self::SINGLE_QUOTE_CLOSE, $single_close, $textnode->data ); |
|
212 | - $textnode->data = preg_replace( self::SINGLE_QUOTE_OPEN_SPECIAL, $single_open, $textnode->data ); // like _'¿hola?'_. |
|
213 | - $textnode->data = preg_replace( self::SINGLE_QUOTE_CLOSE_SPECIAL, $single_close, $textnode->data ); |
|
214 | - $textnode->data = preg_replace( self::DOUBLE_QUOTE_OPEN, $double_open, $textnode->data ); |
|
215 | - $textnode->data = preg_replace( self::DOUBLE_QUOTE_CLOSE, $double_close, $textnode->data ); |
|
216 | - $textnode->data = preg_replace( self::DOUBLE_QUOTE_OPEN_SPECIAL, $double_open, $textnode->data ); |
|
217 | - $textnode->data = preg_replace( self::DOUBLE_QUOTE_CLOSE_SPECIAL, $double_close, $textnode->data ); |
|
209 | + $textnode->data = str_replace($this->brackets_matches, $this->brackets_replacements, $textnode->data); |
|
210 | + $textnode->data = preg_replace(self::SINGLE_QUOTE_OPEN, $single_open, $textnode->data); |
|
211 | + $textnode->data = preg_replace(self::SINGLE_QUOTE_CLOSE, $single_close, $textnode->data); |
|
212 | + $textnode->data = preg_replace(self::SINGLE_QUOTE_OPEN_SPECIAL, $single_open, $textnode->data); // like _'¿hola?'_. |
|
213 | + $textnode->data = preg_replace(self::SINGLE_QUOTE_CLOSE_SPECIAL, $single_close, $textnode->data); |
|
214 | + $textnode->data = preg_replace(self::DOUBLE_QUOTE_OPEN, $double_open, $textnode->data); |
|
215 | + $textnode->data = preg_replace(self::DOUBLE_QUOTE_CLOSE, $double_close, $textnode->data); |
|
216 | + $textnode->data = preg_replace(self::DOUBLE_QUOTE_OPEN_SPECIAL, $double_open, $textnode->data); |
|
217 | + $textnode->data = preg_replace(self::DOUBLE_QUOTE_CLOSE_SPECIAL, $double_close, $textnode->data); |
|
218 | 218 | |
219 | 219 | // Quote catch-alls - assume left over quotes are closing - as this is often the most complicated position, thus most likely to be missed. |
220 | - $textnode->data = str_replace( "'", $single_close, $textnode->data ); |
|
221 | - $textnode->data = str_replace( '"', $double_close, $textnode->data ); |
|
220 | + $textnode->data = str_replace("'", $single_close, $textnode->data); |
|
221 | + $textnode->data = str_replace('"', $double_close, $textnode->data); |
|
222 | 222 | |
223 | 223 | // If we have adjacent characters remove them from the text. |
224 | - $textnode->data = self::remove_adjacent_characters( $textnode->data, $previous_character, $next_character ); |
|
224 | + $textnode->data = self::remove_adjacent_characters($textnode->data, $previous_character, $next_character); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | * @param string $secondary_open Secondary quote style open. |
233 | 233 | * @param string $secondary_close Secondary quote style close. |
234 | 234 | */ |
235 | - private function update_smart_quotes_brackets( $primary_open, $primary_close, $secondary_open, $secondary_close ) { |
|
235 | + private function update_smart_quotes_brackets($primary_open, $primary_close, $secondary_open, $secondary_close) { |
|
236 | 236 | $brackets = [ |
237 | 237 | // Single quotes. |
238 | 238 | "['" => '[' . $secondary_open, |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | "'\"" => $secondary_close . $primary_close, |
256 | 256 | ]; |
257 | 257 | |
258 | - $this->brackets_matches = array_keys( $brackets ); |
|
259 | - $this->brackets_replacements = array_values( $brackets ); |
|
258 | + $this->brackets_matches = array_keys($brackets); |
|
259 | + $this->brackets_replacements = array_values($brackets); |
|
260 | 260 | } |
261 | 261 | } |
@@ -53,7 +53,7 @@ |
||
53 | 53 | * @param string $css_class HTML class used in markup. |
54 | 54 | * @param bool $feed_compatible Optional. Default false. |
55 | 55 | */ |
56 | - public function __construct( $css_class, $feed_compatible = false ) { |
|
57 | - parent::__construct( self::REGEX, self::SETTINGS_SWITCH, $css_class, $feed_compatible ); |
|
56 | + public function __construct($css_class, $feed_compatible = false) { |
|
57 | + parent::__construct(self::REGEX, self::SETTINGS_SWITCH, $css_class, $feed_compatible); |
|
58 | 58 | } |
59 | 59 | } |
@@ -73,40 +73,40 @@ discard block |
||
73 | 73 | * @param Settings $settings Required. |
74 | 74 | * @param bool $is_title Optional. Default false. |
75 | 75 | */ |
76 | - public function apply( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
76 | + public function apply(\DOMText $textnode, Settings $settings, $is_title = false) { |
|
77 | 77 | // Intervening inline tags may interfere with widow identification, but that is a sacrifice of using the parser. |
78 | 78 | // Intervening tags will only interfere if they separate the widow from previous or preceding whitespace. |
79 | - if ( empty( $settings['dewidow'] ) || empty( $settings['dewidowMaxPull'] ) || empty( $settings['dewidowMaxLength'] ) ) { |
|
79 | + if (empty($settings['dewidow']) || empty($settings['dewidowMaxPull']) || empty($settings['dewidowMaxLength'])) { |
|
80 | 80 | return; |
81 | 81 | } |
82 | 82 | |
83 | - if ( '' === DOM::get_next_chr( $textnode ) ) { |
|
83 | + if ('' === DOM::get_next_chr($textnode)) { |
|
84 | 84 | // We have the last type "text" child of a block level element. |
85 | - $textnode->data = preg_replace_callback( self::REGEX, function( array $widow ) use ( $settings ) { |
|
86 | - $func = Strings::functions( $widow[0] ); |
|
85 | + $textnode->data = preg_replace_callback(self::REGEX, function(array $widow) use ($settings) { |
|
86 | + $func = Strings::functions($widow[0]); |
|
87 | 87 | |
88 | 88 | // If we are here, we know that widows are being protected in some fashion |
89 | 89 | // with that, we will assert that widows should never be hyphenated or wrapped |
90 | 90 | // as such, we will strip soft hyphens and zero-width-spaces. |
91 | - $widow['widow'] = str_replace( U::ZERO_WIDTH_SPACE, '', $widow['widow'] ); // TODO: check if this can match here. |
|
92 | - $widow['widow'] = str_replace( U::SOFT_HYPHEN, '', $widow['widow'] ); // TODO: check if this can match here. |
|
93 | - $widow['trailing'] = preg_replace( "/\s+/{$func['u']}", U::NO_BREAK_SPACE, $widow['trailing'] ); |
|
94 | - $widow['trailing'] = str_replace( U::ZERO_WIDTH_SPACE, '', $widow['trailing'] ); |
|
95 | - $widow['trailing'] = str_replace( U::SOFT_HYPHEN, '', $widow['trailing'] ); |
|
91 | + $widow['widow'] = str_replace(U::ZERO_WIDTH_SPACE, '', $widow['widow']); // TODO: check if this can match here. |
|
92 | + $widow['widow'] = str_replace(U::SOFT_HYPHEN, '', $widow['widow']); // TODO: check if this can match here. |
|
93 | + $widow['trailing'] = preg_replace("/\s+/{$func['u']}", U::NO_BREAK_SPACE, $widow['trailing']); |
|
94 | + $widow['trailing'] = str_replace(U::ZERO_WIDTH_SPACE, '', $widow['trailing']); |
|
95 | + $widow['trailing'] = str_replace(U::SOFT_HYPHEN, '', $widow['trailing']); |
|
96 | 96 | |
97 | 97 | // Eject if widows neighbor is proceeded by a no break space (the pulled text would be too long). |
98 | - if ( '' === $widow['space_before'] || strstr( U::NO_BREAK_SPACE, $widow['space_before'] ) ) { |
|
98 | + if ('' === $widow['space_before'] || strstr(U::NO_BREAK_SPACE, $widow['space_before'])) { |
|
99 | 99 | return $widow['space_before'] . $widow['neighbor'] . $widow['space_between'] . $widow['widow'] . $widow['trailing']; |
100 | 100 | } |
101 | 101 | |
102 | 102 | // Eject if widows neighbor length exceeds the max allowed or widow length exceeds max allowed. |
103 | - if ( $func['strlen']( $widow['neighbor'] ) > $settings['dewidowMaxPull'] || |
|
104 | - $func['strlen']( $widow['widow'] ) > $settings['dewidowMaxLength'] ) { |
|
103 | + if ($func['strlen']($widow['neighbor']) > $settings['dewidowMaxPull'] || |
|
104 | + $func['strlen']($widow['widow']) > $settings['dewidowMaxLength']) { |
|
105 | 105 | return $widow['space_before'] . $widow['neighbor'] . $widow['space_between'] . $widow['widow'] . $widow['trailing']; |
106 | 106 | } |
107 | 107 | |
108 | 108 | // Never replace thin and hair spaces with . |
109 | - switch ( $widow['space_between'] ) { |
|
109 | + switch ($widow['space_between']) { |
|
110 | 110 | case U::THIN_SPACE: |
111 | 111 | case U::HAIR_SPACE: |
112 | 112 | return $widow['space_before'] . $widow['neighbor'] . $widow['space_between'] . $widow['widow'] . $widow['trailing']; |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | |
115 | 115 | // Let's protect some widows! |
116 | 116 | return $widow['space_before'] . $widow['neighbor'] . U::NO_BREAK_SPACE . $widow['widow'] . $widow['trailing']; |
117 | - }, $textnode->data ); |
|
117 | + }, $textnode->data); |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | } |
@@ -187,37 +187,37 @@ |
||
187 | 187 | * @param Settings $settings Required. |
188 | 188 | * @param bool $is_title Optional. Default false. |
189 | 189 | */ |
190 | - public function apply( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
191 | - if ( empty( $settings['smartMath'] ) ) { |
|
190 | + public function apply(\DOMText $textnode, Settings $settings, $is_title = false) { |
|
191 | + if (empty($settings['smartMath'])) { |
|
192 | 192 | return; |
193 | 193 | } |
194 | 194 | |
195 | 195 | // First, let's find math equations. |
196 | - $textnode->data = preg_replace_callback( self::MATH_EQUATION, function( array $matches ) { |
|
197 | - $matches[0] = str_replace( '-', U::MINUS, $matches[0] ); |
|
198 | - $matches[0] = str_replace( '/', U::DIVISION, $matches[0] ); |
|
199 | - $matches[0] = str_replace( 'x', U::MULTIPLICATION, $matches[0] ); |
|
200 | - $matches[0] = str_replace( '*', U::MULTIPLICATION, $matches[0] ); |
|
196 | + $textnode->data = preg_replace_callback(self::MATH_EQUATION, function(array $matches) { |
|
197 | + $matches[0] = str_replace('-', U::MINUS, $matches[0]); |
|
198 | + $matches[0] = str_replace('/', U::DIVISION, $matches[0]); |
|
199 | + $matches[0] = str_replace('x', U::MULTIPLICATION, $matches[0]); |
|
200 | + $matches[0] = str_replace('*', U::MULTIPLICATION, $matches[0]); |
|
201 | 201 | |
202 | 202 | return $matches[0]; |
203 | 203 | |
204 | - }, $textnode->data ); |
|
204 | + }, $textnode->data); |
|
205 | 205 | |
206 | 206 | // Revert 4-4 to plain minus-hyphen so as to not mess with ranges of numbers (i.e. pp. 46-50). |
207 | - $textnode->data = preg_replace( self::REVERT_RANGE, '$1-$2', $textnode->data ); |
|
207 | + $textnode->data = preg_replace(self::REVERT_RANGE, '$1-$2', $textnode->data); |
|
208 | 208 | |
209 | 209 | // Revert fractions to basic slash. |
210 | 210 | // We'll leave styling fractions to smart_fractions. |
211 | - $textnode->data = preg_replace( self::REVERT_FRACTION, '$1/$2', $textnode->data ); |
|
211 | + $textnode->data = preg_replace(self::REVERT_FRACTION, '$1/$2', $textnode->data); |
|
212 | 212 | |
213 | 213 | // Revert date back to original formats. |
214 | 214 | // YYYY-MM-DD. |
215 | - $textnode->data = preg_replace( self::REVERT_DATE_YYYY_MM_DD, '$1-$2-$3', $textnode->data ); |
|
215 | + $textnode->data = preg_replace(self::REVERT_DATE_YYYY_MM_DD, '$1-$2-$3', $textnode->data); |
|
216 | 216 | // MM-DD-YYYY or DD-MM-YYYY. |
217 | - $textnode->data = preg_replace( self::REVERT_DATE_MM_DD_YYYY, '$1$3-$2$4-$5', $textnode->data ); |
|
217 | + $textnode->data = preg_replace(self::REVERT_DATE_MM_DD_YYYY, '$1$3-$2$4-$5', $textnode->data); |
|
218 | 218 | // YYYY-MM or YYYY-DDD next. |
219 | - $textnode->data = preg_replace( self::REVERT_DATE_YYYY_MM, '$1-$2', $textnode->data ); |
|
219 | + $textnode->data = preg_replace(self::REVERT_DATE_YYYY_MM, '$1-$2', $textnode->data); |
|
220 | 220 | // MM/DD/YYYY or DD/MM/YYYY. |
221 | - $textnode->data = preg_replace( self::REVERT_DATE_MM_DD_YYYY_SLASHED, '$1$3/$2$4/$5', $textnode->data ); |
|
221 | + $textnode->data = preg_replace(self::REVERT_DATE_MM_DD_YYYY_SLASHED, '$1$3/$2$4/$5', $textnode->data); |
|
222 | 222 | } |
223 | 223 | } |
@@ -49,7 +49,7 @@ |
||
49 | 49 | * |
50 | 50 | * @param bool $feed_compatible Optional. Default false. |
51 | 51 | */ |
52 | - public function __construct( $feed_compatible = false ) { |
|
53 | - parent::__construct( self::REGEX, self::REPLACEMENT, self::SETTING, $feed_compatible ); |
|
52 | + public function __construct($feed_compatible = false) { |
|
53 | + parent::__construct(self::REGEX, self::REPLACEMENT, self::SETTING, $feed_compatible); |
|
54 | 54 | } |
55 | 55 | } |
@@ -58,11 +58,11 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @param bool $feed_compatible Optional. Default false. |
60 | 60 | */ |
61 | - public function __construct( $feed_compatible = false ) { |
|
62 | - parent::__construct( Token_Fix::MIXED_WORDS, $feed_compatible ); |
|
61 | + public function __construct($feed_compatible = false) { |
|
62 | + parent::__construct(Token_Fix::MIXED_WORDS, $feed_compatible); |
|
63 | 63 | |
64 | - $this->hyphens_array = array_unique( [ '-', U::HYPHEN ] ); |
|
65 | - $this->remove_ending_space_regex = '/(' . implode( '|', $this->hyphens_array ) . ')' . U::ZERO_WIDTH_SPACE . '$/'; |
|
64 | + $this->hyphens_array = array_unique(['-', U::HYPHEN]); |
|
65 | + $this->remove_ending_space_regex = '/(' . implode('|', $this->hyphens_array) . ')' . U::ZERO_WIDTH_SPACE . '$/'; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -75,26 +75,26 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return array An array of tokens. |
77 | 77 | */ |
78 | - public function apply( array $tokens, Settings $settings, $is_title = false, \DOMText $textnode = null ) { |
|
79 | - if ( ! empty( $settings['hyphenHardWrap'] ) || ! empty( $settings['smartDashes'] ) ) { |
|
78 | + public function apply(array $tokens, Settings $settings, $is_title = false, \DOMText $textnode = null) { |
|
79 | + if ( ! empty($settings['hyphenHardWrap']) || ! empty($settings['smartDashes'])) { |
|
80 | 80 | |
81 | - foreach ( $tokens as $index => $text_token ) { |
|
81 | + foreach ($tokens as $index => $text_token) { |
|
82 | 82 | $value = $text_token->value; |
83 | 83 | |
84 | - if ( isset( $settings['hyphenHardWrap'] ) && $settings['hyphenHardWrap'] ) { |
|
85 | - $value = str_replace( $this->hyphens_array, '-' . U::ZERO_WIDTH_SPACE, $value ); |
|
86 | - $value = str_replace( '_', '_' . U::ZERO_WIDTH_SPACE, $value ); |
|
87 | - $value = str_replace( '/', '/' . U::ZERO_WIDTH_SPACE, $value ); |
|
84 | + if (isset($settings['hyphenHardWrap']) && $settings['hyphenHardWrap']) { |
|
85 | + $value = str_replace($this->hyphens_array, '-' . U::ZERO_WIDTH_SPACE, $value); |
|
86 | + $value = str_replace('_', '_' . U::ZERO_WIDTH_SPACE, $value); |
|
87 | + $value = str_replace('/', '/' . U::ZERO_WIDTH_SPACE, $value); |
|
88 | 88 | |
89 | - $value = preg_replace( $this->remove_ending_space_regex, '$1', $value ); |
|
89 | + $value = preg_replace($this->remove_ending_space_regex, '$1', $value); |
|
90 | 90 | } |
91 | 91 | |
92 | - if ( ! empty( $settings['smartDashes'] ) ) { |
|
92 | + if ( ! empty($settings['smartDashes'])) { |
|
93 | 93 | // Handled here because we need to know we are inside a word and not a URL. |
94 | - $value = str_replace( '-', U::HYPHEN, $value ); |
|
94 | + $value = str_replace('-', U::HYPHEN, $value); |
|
95 | 95 | } |
96 | 96 | |
97 | - $tokens[ $index ] = $text_token->with_value( $value ); |
|
97 | + $tokens[$index] = $text_token->with_value($value); |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 |
@@ -62,10 +62,10 @@ discard block |
||
62 | 62 | * @param int $target Optional. Default Token_Fix::WORDS. |
63 | 63 | * @param bool $feed_compatible Optional. Default false. |
64 | 64 | */ |
65 | - public function __construct( Hyphenator_Cache $cache = null, $target = Token_Fix::WORDS, $feed_compatible = false ) { |
|
66 | - parent::__construct( $target, $feed_compatible ); |
|
65 | + public function __construct(Hyphenator_Cache $cache = null, $target = Token_Fix::WORDS, $feed_compatible = false) { |
|
66 | + parent::__construct($target, $feed_compatible); |
|
67 | 67 | |
68 | - if ( empty( $cache ) ) { |
|
68 | + if (empty($cache)) { |
|
69 | 69 | $cache = new Hyphenator_Cache(); |
70 | 70 | } |
71 | 71 | |
@@ -89,26 +89,26 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @return array An array of tokens. |
91 | 91 | */ |
92 | - public function apply( array $tokens, Settings $settings, $is_title = false, \DOMText $textnode = null ) { |
|
93 | - if ( empty( $settings['hyphenation'] ) ) { |
|
92 | + public function apply(array $tokens, Settings $settings, $is_title = false, \DOMText $textnode = null) { |
|
93 | + if (empty($settings['hyphenation'])) { |
|
94 | 94 | return $tokens; // abort. |
95 | 95 | } |
96 | 96 | |
97 | 97 | $is_heading = false; |
98 | - if ( ! empty( $textnode ) && ! empty( $textnode->parentNode ) ) { |
|
99 | - $block_level_parent = DOM::get_block_parent_name( $textnode ); |
|
98 | + if ( ! empty($textnode) && ! empty($textnode->parentNode)) { |
|
99 | + $block_level_parent = DOM::get_block_parent_name($textnode); |
|
100 | 100 | |
101 | - if ( ! empty( $block_level_parent ) && isset( $this->heading_tags[ $block_level_parent ] ) ) { |
|
101 | + if ( ! empty($block_level_parent) && isset($this->heading_tags[$block_level_parent])) { |
|
102 | 102 | $is_heading = true; |
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
106 | - if ( empty( $settings['hyphenateTitle'] ) && ( $is_title || $is_heading ) ) { |
|
106 | + if (empty($settings['hyphenateTitle']) && ($is_title || $is_heading)) { |
|
107 | 107 | return $tokens; // abort. |
108 | 108 | } |
109 | 109 | |
110 | 110 | // Call functionality as seperate function so it can be run without test for setting['hyphenation'] - such as with url wrapping. |
111 | - return $this->do_hyphenate( $tokens, $settings ); |
|
111 | + return $this->do_hyphenate($tokens, $settings); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -120,12 +120,12 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @return array The hyphenated text tokens. |
122 | 122 | */ |
123 | - protected function do_hyphenate( array $tokens, Settings $settings, $hyphen = U::SOFT_HYPHEN ) { |
|
124 | - if ( empty( $settings['hyphenMinLength'] ) || empty( $settings['hyphenMinBefore'] ) ) { |
|
123 | + protected function do_hyphenate(array $tokens, Settings $settings, $hyphen = U::SOFT_HYPHEN) { |
|
124 | + if (empty($settings['hyphenMinLength']) || empty($settings['hyphenMinBefore'])) { |
|
125 | 125 | return $tokens; |
126 | 126 | } |
127 | 127 | |
128 | - return $this->get_hyphenator( $settings )->hyphenate( $tokens, $hyphen, ! empty( $settings['hyphenateTitleCase'] ), $settings['hyphenMinLength'], $settings['hyphenMinBefore'], $settings['hyphenMinAfter'] ); |
|
128 | + return $this->get_hyphenator($settings)->hyphenate($tokens, $hyphen, ! empty($settings['hyphenateTitleCase']), $settings['hyphenMinLength'], $settings['hyphenMinBefore'], $settings['hyphenMinAfter']); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -135,17 +135,17 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @return Hyphenator |
137 | 137 | */ |
138 | - public function get_hyphenator( Settings $settings ) { |
|
138 | + public function get_hyphenator(Settings $settings) { |
|
139 | 139 | $lang = $settings['hyphenLanguage']; |
140 | 140 | $exceptions = (array) $settings['hyphenationCustomExceptions']; |
141 | - $hyphenator = $this->cache->get_hyphenator( $lang ); |
|
141 | + $hyphenator = $this->cache->get_hyphenator($lang); |
|
142 | 142 | |
143 | - if ( empty( $hyphenator ) ) { |
|
144 | - $hyphenator = new Hyphenator( $lang, $exceptions ); |
|
145 | - $this->cache->set_hyphenator( $lang, $hyphenator ); |
|
143 | + if (empty($hyphenator)) { |
|
144 | + $hyphenator = new Hyphenator($lang, $exceptions); |
|
145 | + $this->cache->set_hyphenator($lang, $hyphenator); |
|
146 | 146 | } else { |
147 | - $hyphenator->set_language( $lang ); // just for insurance. |
|
148 | - $hyphenator->set_custom_exceptions( $exceptions ); |
|
147 | + $hyphenator->set_language($lang); // just for insurance. |
|
148 | + $hyphenator->set_custom_exceptions($exceptions); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | return $hyphenator; |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * |
157 | 157 | * @param Hyphenator_Cache $cache Required. |
158 | 158 | */ |
159 | - public function set_hyphenator_cache( Hyphenator_Cache $cache ) { |
|
159 | + public function set_hyphenator_cache(Hyphenator_Cache $cache) { |
|
160 | 160 | $this->cache = $cache; |
161 | 161 | } |
162 | 162 | } |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @param bool $feed_compatible Optional. Default false. |
56 | 56 | */ |
57 | - public function __construct( $feed_compatible = false ) { |
|
58 | - parent::__construct( Token_Fix::OTHER, $feed_compatible ); |
|
57 | + public function __construct($feed_compatible = false) { |
|
58 | + parent::__construct(Token_Fix::OTHER, $feed_compatible); |
|
59 | 59 | |
60 | 60 | $this->email_pattern = "/(?: |
61 | 61 | \A |
@@ -88,16 +88,16 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @return array An array of tokens. |
90 | 90 | */ |
91 | - public function apply( array $tokens, Settings $settings, $is_title = false, \DOMText $textnode = null ) { |
|
92 | - if ( empty( $settings['emailWrap'] ) ) { |
|
91 | + public function apply(array $tokens, Settings $settings, $is_title = false, \DOMText $textnode = null) { |
|
92 | + if (empty($settings['emailWrap'])) { |
|
93 | 93 | return $tokens; |
94 | 94 | } |
95 | 95 | |
96 | 96 | // Test for and parse urls. |
97 | - foreach ( $tokens as $index => $token ) { |
|
97 | + foreach ($tokens as $index => $token) { |
|
98 | 98 | $value = $token->value; |
99 | - if ( preg_match( $this->email_pattern, $value, $email_match ) ) { |
|
100 | - $tokens[ $index ] = $token->with_value( preg_replace( self::REPLACE_EMAILS, '$1' . U::ZERO_WIDTH_SPACE, $value ) ); |
|
99 | + if (preg_match($this->email_pattern, $value, $email_match)) { |
|
100 | + $tokens[$index] = $token->with_value(preg_replace(self::REPLACE_EMAILS, '$1' . U::ZERO_WIDTH_SPACE, $value)); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | * @param Hyphenator_Cache|null $cache Optional. Default null. |
49 | 49 | * @param bool $feed_compatible Optional. Default false. |
50 | 50 | */ |
51 | - public function __construct( Hyphenator_Cache $cache = null, $feed_compatible = false ) { |
|
52 | - parent::__construct( $cache, Token_Fix::COMPOUND_WORDS, $feed_compatible ); |
|
51 | + public function __construct(Hyphenator_Cache $cache = null, $feed_compatible = false) { |
|
52 | + parent::__construct($cache, Token_Fix::COMPOUND_WORDS, $feed_compatible); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -62,21 +62,21 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return array An array of tokens. |
64 | 64 | */ |
65 | - public function apply( array $tokens, Settings $settings, $is_title = false, \DOMText $textnode = null ) { |
|
66 | - if ( empty( $settings['hyphenateCompounds'] ) ) { |
|
65 | + public function apply(array $tokens, Settings $settings, $is_title = false, \DOMText $textnode = null) { |
|
66 | + if (empty($settings['hyphenateCompounds'])) { |
|
67 | 67 | return $tokens; // abort. |
68 | 68 | } |
69 | 69 | |
70 | 70 | // Hyphenate compound words. |
71 | - foreach ( $tokens as $key => $word_token ) { |
|
71 | + foreach ($tokens as $key => $word_token) { |
|
72 | 72 | $component_words = []; |
73 | - foreach ( preg_split( '/(-)/', $word_token->value, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ) as $word_part ) { |
|
74 | - $component_words[] = new Text_Parser\Token( $word_part, Text_Parser\Token::WORD ); |
|
73 | + foreach (preg_split('/(-)/', $word_token->value, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $word_part) { |
|
74 | + $component_words[] = new Text_Parser\Token($word_part, Text_Parser\Token::WORD); |
|
75 | 75 | } |
76 | 76 | |
77 | - $tokens[ $key ] = $word_token->with_value( array_reduce( parent::apply( $component_words, $settings, $is_title, $textnode ), function( $carry, $item ) { |
|
77 | + $tokens[$key] = $word_token->with_value(array_reduce(parent::apply($component_words, $settings, $is_title, $textnode), function($carry, $item) { |
|
78 | 78 | return $carry . $item->value; |
79 | - } ) ); |
|
79 | + } )); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | return $tokens; |