Conditions | 12 |
Paths | 92 |
Total Lines | 85 |
Code Lines | 48 |
Lines | 0 |
Ratio | 0 % |
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 |
||
169 | private static function _is_regexp_spam( $comment ) { |
||
170 | /* Felder */ |
||
171 | $fields = array( |
||
172 | 'ip', |
||
173 | 'host', |
||
174 | 'body', |
||
175 | 'email', |
||
176 | 'author', |
||
177 | ); |
||
178 | |||
179 | /* Regexp */ |
||
180 | $patterns = array( |
||
181 | 0 => array( |
||
182 | 'host' => '^(www\.)?\d+\w+\.com$', |
||
183 | 'body' => '^\w+\s\d+$', |
||
184 | 'email' => '@gmail.com$', |
||
185 | ), |
||
186 | 1 => array( |
||
187 | 'body' => '\<\!.+?mfunc.+?\>', |
||
188 | ) |
||
189 | ); |
||
190 | |||
191 | /* Spammy author */ |
||
192 | if ( $quoted_author = preg_quote( $comment['author'], '/' ) ) { |
||
193 | $patterns[] = array( |
||
194 | 'body' => sprintf( |
||
195 | '<a.+?>%s<\/a>$', |
||
196 | $quoted_author |
||
197 | ) |
||
198 | ); |
||
199 | $patterns[] = array( |
||
200 | 'body' => sprintf( |
||
201 | '%s https?:.+?$', |
||
202 | $quoted_author |
||
203 | ) |
||
204 | ); |
||
205 | $patterns[] = array( |
||
206 | 'email' => '@gmail.com$', |
||
207 | 'author' => '^[a-z0-9-\.]+\.[a-z]{2,6}$', |
||
208 | 'host' => sprintf( |
||
209 | '^%s$', |
||
210 | $quoted_author |
||
211 | ) |
||
212 | ); |
||
213 | } |
||
214 | |||
215 | /* Hook */ |
||
216 | $patterns = apply_filters( |
||
217 | 'antispam_bee_patterns', |
||
218 | $patterns |
||
219 | ); |
||
220 | |||
221 | if ( ! $patterns ) { |
||
222 | return false; |
||
223 | } |
||
224 | |||
225 | foreach ( $patterns as $pattern ) { |
||
226 | $hits = array(); |
||
227 | |||
228 | foreach ( $pattern as $field => $regexp ) { |
||
229 | $is_empty = ( empty( $field ) || ! in_array( $field, $fields ) || empty( $regexp ) ); |
||
230 | if ( $is_empty ) { |
||
231 | continue; |
||
232 | } |
||
233 | |||
234 | /* Ignore non utf-8 chars */ |
||
235 | $comment[ $field ] = ( function_exists('iconv') ? iconv( 'utf-8', 'utf-8//TRANSLIT', $comment[ $field ] ) : $comment[ $field ] ); |
||
236 | |||
237 | if ( empty( $comment[ $field ] ) ) { |
||
238 | continue; |
||
239 | } |
||
240 | |||
241 | /* Perform regex */ |
||
242 | if ( preg_match( '/' .$regexp. '/isu', $comment[ $field ] ) ) { |
||
243 | $hits[ $field ] = true; |
||
244 | } |
||
245 | } |
||
246 | |||
247 | if ( count( $hits ) === count( $pattern ) ) { |
||
248 | return true; |
||
249 | } |
||
250 | } |
||
251 | |||
252 | return false; |
||
253 | } |
||
254 | |||
281 |