Conditions | 41 |
Paths | 204 |
Total Lines | 92 |
Code Lines | 53 |
Lines | 4 |
Ratio | 4.35 % |
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 |
||
68 | public function checkSecurity() { |
||
69 | |||
70 | foreach (Config::get('Route') as $sHost => $oHost) { |
||
|
|||
71 | |||
72 | if ((!strstr($sHost, '/') && $sHost == $_SERVER['HTTP_HOST']) |
||
73 | || (strstr($sHost, '/') && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost))) { |
||
74 | |||
75 | View Code Duplication | if (strstr($sHost, '/') && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost)) { |
|
76 | |||
77 | $this->_sBaseUri = preg_replace('#^[^/]+#', '', $sHost); |
||
78 | } |
||
79 | |||
80 | if (isset($oSecurity->firewall)) { $oSecurity = $oHost->firewall; } |
||
81 | } |
||
82 | } |
||
83 | |||
84 | if (isset($oSecurity)) { |
||
85 | |||
86 | if (isset($oSecurity->authentification) && $oSecurity->authentification === 'http_basic') { |
||
87 | |||
88 | if (!isset($_SERVER['PHP_AUTH_USER'])) { |
||
89 | |||
90 | if (!isset($oSecurity->realm)) { $oSecurity->realm = 'Access'; } |
||
91 | if (!isset($oSecurity->cancelled)) { $oSecurity->cancelled = 'Cancelled'; } |
||
92 | |||
93 | header('WWW-Authenticate: Basic realm="'.$oSecurity->realm.'"'); |
||
94 | header('HTTP/1.0 401 Unauthorized'); |
||
95 | echo $oSecurity->cancelled; |
||
96 | exit; |
||
97 | } else { |
||
98 | |||
99 | self::$_sLogin = $_SERVER['PHP_AUTH_USER']; |
||
100 | self::$_sPassword = $_SERVER['PHP_AUTH_PW']; |
||
101 | |||
102 | if (!$this->_checkPasswordIsGood()) { return false; } |
||
103 | if (!$this->_checkAccess()) { return false; } |
||
104 | if (!$this->_checkBlackListIps()) { return false; } |
||
105 | } |
||
106 | } |
||
107 | else if (isset($oSecurity->authentification) && $oSecurity->authentification === 'http_basic_validate_by_controller') { |
||
108 | |||
109 | if (!isset($_SERVER['PHP_AUTH_USER'])) { |
||
110 | |||
111 | if (!isset($oSecurity->realm)) { $oSecurity->realm = 'Access'; } |
||
112 | if (!isset($oSecurity->cancelled)) { $oSecurity->cancelled = 'Cancelled'; } |
||
113 | |||
114 | header('WWW-Authenticate: Basic realm="'.$oSecurity->realm.'"'); |
||
115 | header('HTTP/1.0 401 Unauthorized'); |
||
116 | echo $oSecurity->cancelled; |
||
117 | exit; |
||
118 | } else { |
||
119 | |||
120 | self::$_sLogin = $_SERVER['PHP_AUTH_USER']; |
||
121 | self::$_sPassword = $_SERVER['PHP_AUTH_PW']; |
||
122 | |||
123 | $sControllerName = $oSecurity->controller; |
||
124 | $sActionName = $oSecurity->action; |
||
125 | |||
126 | $oController = new $sControllerName; |
||
127 | |||
128 | if (!$oController->$sActionName(self::$_sLogin, self::$_sPassword)) { return false; } |
||
129 | if (!$this->_checkAccess()) { return false; } |
||
130 | if (!$this->_checkBlackListIps()) { return false; } |
||
131 | } |
||
132 | } else if (isset($oSecurity->authentification) && $oSecurity->authentification === 'controller') { |
||
133 | |||
134 | // it's an action of one controller that it return true or false for the authentification |
||
135 | |||
136 | $sControllerName = $oSecurity->controller; |
||
137 | $sActionName = $oSecurity->action; |
||
138 | |||
139 | $oController = new $sControllerName; |
||
140 | |||
141 | if (!$oController->$sActionName) { return false; } |
||
142 | if (!$this->_checkAccess()) { return false; } |
||
143 | if (!$this->_checkBlackListIps()) { return false; } |
||
144 | } |
||
145 | |||
146 | if (isset($oSecurity->ips) && !in_array($_SERVER['REMOTE_ADDR'], $oSecurity->ips)) { return false; } |
||
147 | |||
148 | if (isset($oSecurity->requires_channel) && $oSecurity->requires_channel == 'https' && !Request::isHttpsRequest()) { |
||
149 | |||
150 | return false; |
||
151 | } else if (isset($oSecurity->requires_channel) && $oSecurity->requires_channel == 'http' && ((Request::isHttpRequest() |
||
152 | && Request::isHttpsRequest()) || !Request::isHttpRequest())) { |
||
153 | |||
154 | return false; |
||
155 | } |
||
156 | } |
||
157 | |||
158 | return true; |
||
159 | } |
||
160 | |||
271 |