Conditions | 13 |
Paths | 28 |
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 |
||
126 | protected function section() { |
||
127 | |||
128 | # Check site status |
||
129 | |||
130 | if (Settings::get('site_status') === STATUS_MAINTENANCE) return Status::maintenance(); |
||
131 | |||
132 | if (Settings::get('site_status') === STATUS_UPDATE) return Status::update(); |
||
133 | |||
134 | # Check access rights |
||
135 | |||
136 | if ($this instanceof Component\Profile) { |
||
137 | |||
138 | if (!Settings::get('users_registration')) return Status::error404(); |
||
139 | |||
140 | if (($this instanceof Component\Profile\Auth)) { |
||
141 | |||
142 | if (Auth::check()) Request::redirect(INSTALL_PATH . '/profile'); |
||
143 | |||
144 | View Code Duplication | } else if (!Auth::check() || ((false !== Request::get('logout')) && Auth::logout())) { |
|
|
|||
145 | |||
146 | Request::redirect(INSTALL_PATH . '/profile/login'); |
||
147 | } |
||
148 | } |
||
149 | |||
150 | # Handle request |
||
151 | |||
152 | if (Template::isBlock($result = $this->handle())) { |
||
153 | |||
154 | # Set global components |
||
155 | |||
156 | $variables = new Variables(); $widgets = new Widgets(); |
||
157 | |||
158 | foreach ($variables->items() as $name => $value) Template::global($name, $value); |
||
159 | |||
160 | foreach ($widgets->items() as $name => $block) Template::widget($name, $block); |
||
161 | |||
162 | # Display page |
||
163 | |||
164 | return $this->displayPage($result); |
||
165 | } |
||
166 | |||
167 | # ------------------------ |
||
168 | |||
169 | return Status::error404(); |
||
170 | } |
||
171 | } |
||
173 |
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.