Conditions | 17 |
Paths | 26 |
Total Lines | 45 |
Code Lines | 15 |
Lines | 4 |
Ratio | 8.89 % |
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 |
||
139 | protected function section() { |
||
140 | |||
141 | # Check for restricted access |
||
142 | |||
143 | if (('' === CONFIG_ADMIN_IP) || in_array(REQUEST_CLIENT_IP, preg_split('/ +/', CONFIG_ADMIN_IP))) { |
||
144 | |||
145 | # Handle install component request |
||
146 | |||
147 | if ($this instanceof Component\Install) { |
||
148 | |||
149 | if (Template::isBlock($result = $this->handle())) return $this->displayForm($result, STATUS_CODE_200); |
||
150 | } |
||
151 | |||
152 | # Handle auth component request |
||
153 | |||
154 | else if ($this instanceof Component\Auth) { |
||
155 | |||
156 | if (Auth::check()) Request::redirect(INSTALL_PATH . '/admin'); |
||
157 | |||
158 | if ($this instanceof Component\Auth\Initial) { if (!Auth::initial()) Request::redirect(INSTALL_PATH . '/admin/login'); } |
||
159 | |||
160 | else if (Auth::initial()) Request::redirect(INSTALL_PATH . '/admin/register'); |
||
161 | |||
162 | if (Template::isBlock($result = $this->handle())) return $this->displayForm($result, STATUS_CODE_401); |
||
163 | } |
||
164 | |||
165 | # Handle panel component request |
||
166 | |||
167 | else if ($this instanceof Component\Panel) { |
||
168 | |||
169 | View Code Duplication | if (!Auth::check() || ((false !== Request::get('logout')) && Auth::logout())) { |
|
|
|||
170 | |||
171 | Request::redirect(INSTALL_PATH . '/admin/login'); |
||
172 | } |
||
173 | |||
174 | if (Template::isBlock($result = $this->handle())) return $this->displayPage($result); |
||
175 | |||
176 | if (Ajax::isResponse($result)) return Ajax::output($result); |
||
177 | } |
||
178 | } |
||
179 | |||
180 | # ------------------------ |
||
181 | |||
182 | return Status::error404(); |
||
183 | } |
||
184 | } |
||
186 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.