| Conditions | 12 |
| Paths | 36 |
| Total Lines | 86 |
| Code Lines | 47 |
| 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 |
||
| 148 | private static function _is_regexp_spam( $comment ) { |
||
| 149 | /* Felder */ |
||
| 150 | $fields = array( |
||
| 151 | 'ip', |
||
| 152 | 'host', |
||
| 153 | 'body', |
||
| 154 | 'email', |
||
| 155 | 'author' |
||
| 156 | ); |
||
| 157 | |||
| 158 | /* Regexp */ |
||
| 159 | $patterns = array( |
||
| 160 | 0 => array( |
||
| 161 | 'host' => '^(www\.)?\d+\w+\.com$', |
||
| 162 | 'body' => '^\w+\s\d+$', |
||
| 163 | 'email' => '@gmail.com$' |
||
| 164 | ), |
||
| 165 | 1 => array( |
||
| 166 | 'body' => '\<\!.+?mfunc.+?\>' |
||
| 167 | ) |
||
| 168 | ); |
||
| 169 | |||
| 170 | /* Spammy author */ |
||
| 171 | if ( $quoted_author = preg_quote($comment['author'], '/') ) { |
||
| 172 | $patterns[] = array( |
||
| 173 | 'body' => sprintf( |
||
| 174 | '<a.+?>%s<\/a>$', |
||
| 175 | $quoted_author |
||
| 176 | ) |
||
| 177 | ); |
||
| 178 | $patterns[] = array( |
||
| 179 | 'body' => sprintf( |
||
| 180 | '%s https?:.+?$', |
||
| 181 | $quoted_author |
||
| 182 | ) |
||
| 183 | ); |
||
| 184 | $patterns[] = array( |
||
| 185 | 'email' => '@gmail.com$', |
||
| 186 | 'author' => '^[a-z0-9-\.]+\.[a-z]{2,6}$', |
||
| 187 | 'host' => sprintf( |
||
| 188 | '^%s$', |
||
| 189 | $quoted_author |
||
| 190 | ) |
||
| 191 | ); |
||
| 192 | } |
||
| 193 | |||
| 194 | /* Hook */ |
||
| 195 | $patterns = apply_filters( |
||
| 196 | 'antispam_bee_patterns', |
||
| 197 | $patterns |
||
| 198 | ); |
||
| 199 | |||
| 200 | if ( ! $patterns ) { |
||
| 201 | return false; |
||
| 202 | } |
||
| 203 | |||
| 204 | foreach ($patterns as $pattern) { |
||
| 205 | $hits = array(); |
||
| 206 | |||
| 207 | foreach ($pattern as $field => $regexp) { |
||
| 208 | /* Empty value? */ |
||
| 209 | if ( empty($field) OR !in_array($field, $fields) OR empty($regexp) ) { |
||
| 210 | continue; |
||
| 211 | } |
||
| 212 | |||
| 213 | /* Ignore non utf-8 chars */ |
||
| 214 | $comment[$field] = ( function_exists('iconv') ? iconv('utf-8', 'utf-8//TRANSLIT', $comment[$field]) : $comment[$field] ); |
||
| 215 | |||
| 216 | /* Empty value? */ |
||
| 217 | if ( empty($comment[$field]) ) { |
||
| 218 | continue; |
||
| 219 | } |
||
| 220 | |||
| 221 | /* Perform regex */ |
||
| 222 | if ( @preg_match('/' .$regexp. '/isu', $comment[$field]) ) { |
||
| 223 | $hits[$field] = true; |
||
| 224 | } |
||
| 225 | } |
||
| 226 | |||
| 227 | if ( count($hits) === count($pattern) ) { |
||
| 228 | return true; |
||
| 229 | } |
||
| 230 | } |
||
| 231 | |||
| 232 | return false; |
||
| 233 | } |
||
| 234 | |||
| 264 |