We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 2 |
Paths | 2 |
Total Lines | 53 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Tests | 25 |
CRAP Score | 2 |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
134 | 24 | public function apply( \DOMText $textnode, Settings $settings, $is_title = false ) { |
|
135 | 24 | if ( empty( $settings[ Settings::SMART_DASHES ] ) ) { |
|
136 | 12 | return; |
|
137 | } |
||
138 | |||
139 | // Various special characters and regular expressions. |
||
140 | 12 | $s = $settings->dash_style(); |
|
141 | |||
142 | // Cache textnode content. |
||
143 | 12 | $node_data = $textnode->data; |
|
144 | |||
145 | 12 | $node_data = \str_replace( '---', U::EM_DASH, $node_data ); |
|
146 | 12 | $node_data = \preg_replace( self::PARENTHETICAL_DOUBLE_DASH, "\$1{$s->parenthetical_dash()}\$2", $node_data ); |
|
147 | 12 | $node_data = \str_replace( '--', U::EN_DASH, $node_data ); |
|
148 | |||
149 | 12 | $node_data = \preg_replace( |
|
150 | [ |
||
151 | 12 | self::PARENTHETICAL_SINGLE_DASH, |
|
152 | 12 | self::EN_DASH_WORDS, |
|
153 | 12 | self::EN_DASH_NUMBERS, |
|
154 | 12 | self::EN_DASH_PHONE_NUMBERS, |
|
155 | 12 | self::NO_BREAK_HYPHEN, |
|
156 | ], |
||
157 | [ |
||
158 | 12 | "\$1{$s->parenthetical_dash()}\$2", |
|
159 | '$1' . U::EN_DASH . '$2', |
||
160 | 12 | "\$1{$s->interval_dash()}\$3", |
|
161 | '$1' . U::NO_BREAK_HYPHEN . '$2', |
||
162 | '$1' . U::NO_BREAK_HYPHEN . '$2', |
||
163 | ], |
||
164 | 12 | $node_data |
|
165 | ); |
||
166 | |||
167 | // Revert messed-up punycode. |
||
168 | 12 | $node_data = \str_replace( 'xn' . U::EN_DASH, 'xn--', $node_data ); |
|
169 | |||
170 | // Revert dates back to original formats. |
||
171 | 12 | $node_data = \preg_replace( |
|
172 | [ |
||
173 | 12 | self::DATE_YYYY_MM_DD, // YYYY-MM-DD. |
|
174 | 12 | self::DATE_MM_DD_YYYY, // MM-DD-YYYY or DD-MM-YYYY. |
|
175 | 12 | self::DATE_YYYY_MM, // YYYY-MM or YYYY-DDDD. |
|
176 | ], |
||
177 | [ |
||
178 | 12 | '$1-$2-$3', |
|
179 | '$1$3-$2$4-$5', |
||
180 | '$1-$2', |
||
181 | ], |
||
182 | 12 | $node_data |
|
183 | ); |
||
184 | |||
185 | // Restore textnode content. |
||
186 | 12 | $textnode->data = $node_data; |
|
187 | 12 | } |
|
189 |