| Total Complexity | 40 |
| Total Lines | 173 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Core often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Core, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 9 | class Core |
||
| 10 | { |
||
| 11 | protected function eventFailedLogin(){ |
||
| 41 | |||
| 42 | } |
||
| 43 | protected function eventCleanLockoutAccount(){ |
||
| 46 | |||
| 47 | } |
||
| 48 | protected function logging($middleware="WEB"){ |
||
| 49 | if(config('irfa.lockout.logging')){ |
||
| 50 | Log::notice($middleware." | Login attemps fail | "."username : ".Request::input(config('irfa.lockout.input_name'))." | ipAddress : ".Request::ip()." | userAgent : ".$_SERVER['HTTP_USER_AGENT'].PHP_EOL); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | protected function showMessage(){ |
||
| 54 | if(Session::has(config('irfa.lockout.message_name'))){ |
||
| 55 | return Session::get(config('irfa.lockout.message_name')); |
||
| 56 | } |
||
| 57 | |||
| 58 | return null; |
||
| 59 | } |
||
| 60 | protected function lockLogin(){ |
||
| 61 | $ip = Request::ip(); |
||
| 62 | $matchip= empty(config('irfa.lockout.match_ip'))?false:config('irfa.lockout.match_ip'); |
||
| 63 | $dir = config('irfa.lockout.lockout_file_path'); |
||
| 64 | $attemps = config('irfa.lockout.login_attemps'); |
||
| 65 | $path = $dir.md5(Request::input('email')); |
||
| 66 | if(File::exists($path)) |
||
| 67 | { |
||
| 68 | $get = json_decode(File::get($path)); |
||
| 69 | // dd($get->attemps.">".$attemps); |
||
| 70 | if($get->attemps == "lock"){ |
||
| 71 | return true; |
||
| 72 | } |
||
| 73 | if($get->attemps > $attemps){ |
||
| 74 | if($matchip){ |
||
| 75 | if($this->checkIp($ip_list,$ip)){ |
||
| 76 | return true; |
||
| 77 | } else{ |
||
| 78 | return false; |
||
| 79 | } |
||
| 80 | } else{ |
||
| 81 | return true; |
||
| 82 | } |
||
| 83 | } else{ |
||
| 84 | return false; |
||
| 85 | } |
||
| 86 | } else{ |
||
| 87 | return false; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | private function checkIp($ip_list,$ip){ |
||
| 91 | if(collect($ip_list)->contains($ip)){ |
||
| 92 | return true; |
||
| 93 | } else{ |
||
| 94 | return false; |
||
| 95 | } |
||
| 96 | |||
| 97 | } |
||
| 98 | public function clear_all(){ |
||
| 104 | } |
||
| 105 | } |
||
| 106 | public function unlock_account($username){ |
||
| 107 | $ip = Request::ip(); |
||
| 108 | $matchip= empty(config('irfa.lockout.match_ip'))?false:config('irfa.lockout.match_ip'); |
||
| 109 | $dir = config('irfa.lockout.lockout_file_path'); |
||
| 110 | $attemps = config('irfa.lockout.attemps'); |
||
| 111 | $path = $dir.md5($username); |
||
| 112 | |||
| 113 | if(File::exists($path)){ |
||
| 114 | $readf = File::get($path); |
||
| 115 | File::delete($path); |
||
| 116 | if(php_sapi_name() == "cli"){ |
||
| 117 | echo Lang::get('lockoutMessage.user_unlock_success')."\n"; |
||
| 118 | return $readf; |
||
| 119 | |||
| 120 | } else{ |
||
| 121 | return true; |
||
| 122 | } |
||
| 123 | } else{ |
||
| 124 | if(php_sapi_name() == "cli"){ |
||
| 125 | echo Lang::get('lockoutMessage.user_lock_404')."\n"; |
||
| 126 | exit(); |
||
| 127 | } else{ |
||
| 128 | return false; |
||
| 129 | } |
||
| 130 | } |
||
| 131 | } |
||
| 132 | public function check_account($username){ |
||
| 151 | } |
||
| 152 | } |
||
| 153 | } |
||
| 154 | |||
| 155 | public function lock_account($username){ |
||
| 182 | } |
||
| 183 | } |
||
| 185 | } |