| Conditions | 9 | 
| Paths | 66 | 
| Total Lines | 71 | 
| 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  | 
            ||
| 52 | private function IsRuleExist()  | 
            ||
| 53 |     { | 
            ||
| 54 | $ipRule = $this->driver->get($this->ip, 'rule');  | 
            ||
| 55 | |||
| 56 |         if (empty($ipRule)) { | 
            ||
| 57 | return false;  | 
            ||
| 58 | }  | 
            ||
| 59 | |||
| 60 | $ruleType = (int) $ipRule['type'];  | 
            ||
| 61 | |||
| 62 | // Apply the status code.  | 
            ||
| 63 | $this->result = $ruleType;  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 64 | |||
| 65 |         if ($ruleType === kernel::ACTION_ALLOW) { | 
            ||
| 66 | return true;  | 
            ||
| 67 | }  | 
            ||
| 68 | |||
| 69 | // Current visitor has been blocked. If he still attempts accessing the site,  | 
            ||
| 70 | // then we can drop him into the permanent block list.  | 
            ||
| 71 | $attempts = $ipRule['attempts'] ?? 0;  | 
            ||
| 72 | $attempts = (int) $attempts;  | 
            ||
| 73 | $now = time();  | 
            ||
| 74 | $logData = [];  | 
            ||
| 75 | $handleType = 0;  | 
            ||
| 76 | |||
| 77 | $logData['log_ip'] = $ipRule['log_ip'];  | 
            ||
| 78 | $logData['ip_resolve'] = $ipRule['ip_resolve'];  | 
            ||
| 79 | $logData['time'] = $now;  | 
            ||
| 80 | $logData['type'] = $ipRule['type'];  | 
            ||
| 81 | $logData['reason'] = $ipRule['reason'];  | 
            ||
| 82 | $logData['attempts'] = $attempts;  | 
            ||
| 83 | |||
| 84 | // @since 0.2.0  | 
            ||
| 85 | $attemptPeriod = $this->properties['record_attempt_detection_period'];  | 
            ||
| 86 | $attemptReset = $this->properties['reset_attempt_counter'];  | 
            ||
| 87 | |||
| 88 | $lastTimeDiff = $now - $ipRule['time'];  | 
            ||
| 89 | |||
| 90 |         if ($lastTimeDiff <= $attemptPeriod) { | 
            ||
| 91 | $logData['attempts'] = ++$attempts;  | 
            ||
| 92 | }  | 
            ||
| 93 | |||
| 94 |         if ($lastTimeDiff > $attemptReset) { | 
            ||
| 95 | $logData['attempts'] = 0;  | 
            ||
| 96 | }  | 
            ||
| 97 | |||
| 98 |         if ($ruleType === kernel::ACTION_TEMPORARILY_DENY) { | 
            ||
| 99 | $ratd = $this->determineAttemptsTemporaryDeny($logData, $handleType, $attempts);  | 
            ||
| 100 | $logData = $ratd['log_data'];  | 
            ||
| 101 | $handleType = $ratd['handle_type'];  | 
            ||
| 102 | }  | 
            ||
| 103 | |||
| 104 |         if ($ruleType === kernel::ACTION_DENY) { | 
            ||
| 105 | $rapd = $this->determineAttemptsPermanentDeny($logData, $handleType, $attempts);  | 
            ||
| 106 | $logData = $rapd['log_data'];  | 
            ||
| 107 | $handleType = $rapd['handle_type'];  | 
            ||
| 108 | }  | 
            ||
| 109 | |||
| 110 | // We only update data when `deny_attempt_enable` is enable.  | 
            ||
| 111 | // Because we want to get the last visited time and attempt counter.  | 
            ||
| 112 | // Otherwise, we don't update it everytime to avoid wasting CPU resource.  | 
            ||
| 113 |         if ($this->event['update_rule_table']) { | 
            ||
| 114 | $this->driver->save($this->ip, $logData, 'rule');  | 
            ||
| 115 | }  | 
            ||
| 116 | |||
| 117 | // Notify this event to messenger.  | 
            ||
| 118 |         if ($this->event['trigger_messengers']) { | 
            ||
| 119 | $this->prepareMessengerBody($logData, $handleType);  | 
            ||
| 120 | }  | 
            ||
| 121 | |||
| 122 | return true;  | 
            ||
| 123 | }  | 
            ||
| 248 |