Conditions | 14 |
Paths | 11 |
Total Lines | 65 |
Code Lines | 38 |
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 |
||
9 | private static function is_spam( $comment ) { |
||
|
|||
10 | $url = $email = $author = $body = $comment; // TODO: get values from form |
||
11 | $options = array( |
||
12 | 'time_check' => 1, 'bbcode_check' => 1, |
||
13 | 'advanced_check' => 1, 'regexp_check' => 1, |
||
14 | 'dnsbl_check' => 1, |
||
15 | ); |
||
16 | |||
17 | $response = array( 'spam' => false ); |
||
18 | |||
19 | /* Check if logged in */ |
||
20 | if ( is_user_logged_in() ) { |
||
21 | return $response; |
||
22 | } |
||
23 | |||
24 | /* Honeypot */ |
||
25 | if ( ! empty( $_POST['ab_spam__hidden_field'] ) ) { |
||
26 | $response['reason'] = 'css'; |
||
27 | return $response; |
||
28 | } |
||
29 | |||
30 | $ip = FrmAppHelper::get_ip_address(); |
||
31 | if ( empty( $ip ) ) { |
||
32 | $response['reason'] = 'empty'; |
||
33 | return $response; |
||
34 | } |
||
35 | |||
36 | /* Action time */ |
||
37 | if ( $options['time_check'] && self::_is_shortest_time() ) { |
||
38 | $response['reason'] = 'time'; |
||
39 | return $response; |
||
40 | } |
||
41 | |||
42 | /* BBCode Spam */ |
||
43 | if ( $options['bbcode_check'] && self::_is_bbcode_spam( $body ) ) { |
||
44 | $response['reason'] = 'bbcode'; |
||
45 | return $response; |
||
46 | } |
||
47 | |||
48 | if ( $options['advanced_check'] && self::_is_fake_ip( $ip ) ) { |
||
49 | $response['reason'] = 'server'; |
||
50 | return $response; |
||
51 | } |
||
52 | |||
53 | /* Regexp for Spam */ |
||
54 | if ( $options['regexp_check'] ) { |
||
55 | $is_spam = self::_is_regexp_spam( array( |
||
56 | 'ip' => $ip, |
||
57 | 'host' => parse_url( $url, PHP_URL_HOST ), |
||
58 | 'body' => $body, |
||
59 | 'email' => $email, |
||
60 | 'author' => $author, |
||
61 | ) ); |
||
62 | if ( $is_spam ) { |
||
63 | $response['reason'] = 'regexp'; |
||
64 | return $response; |
||
65 | } |
||
66 | } |
||
67 | |||
68 | /* DNSBL Spam */ |
||
69 | if ( $options['dnsbl_check'] && self::_is_dnsbl_spam( $ip ) ) { |
||
70 | $response['reason'] = 'dnsbl'; |
||
71 | return $response; |
||
72 | } |
||
73 | } |
||
74 | |||
281 |