Conditions | 15 |
Paths | 324 |
Total Lines | 68 |
Code Lines | 43 |
Lines | 10 |
Ratio | 14.71 % |
Changes | 3 | ||
Bugs | 1 | Features | 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 |
||
131 | public static function run() |
||
132 | { |
||
133 | $html = null; |
||
134 | // lets try to get html full content to page render |
||
135 | try { |
||
136 | /** @var \Ffcms\Core\Arch\Controller $callClass */ |
||
137 | $callClass = null; |
||
138 | $callMethod = 'action' . self::$Request->getAction(); |
||
139 | |||
140 | // founded callback injection alias |
||
141 | if (self::$Request->getCallbackAlias() !== false) { |
||
142 | $cName = self::$Request->getCallbackAlias(); |
||
143 | View Code Duplication | if (class_exists($cName)) { |
|
144 | $callClass = new $cName; |
||
145 | } else { |
||
146 | throw new NotFoundException('Callback alias of class "' . App::$Security->strip_tags($cName) . '" is not founded'); |
||
147 | } |
||
148 | } else { // typical parsing of native apps |
||
149 | $cName = '\Apps\Controller\\' . env_name . '\\' . self::$Request->getController(); |
||
150 | |||
151 | // try to initialize class object |
||
152 | View Code Duplication | if (class_exists($cName)) { |
|
153 | $callClass = new $cName; |
||
154 | } else { |
||
155 | throw new NotFoundException('Application can not be runned. Initialized class not founded: ' . App::$Security->strip_tags($cName)); |
||
156 | } |
||
157 | } |
||
158 | |||
159 | // try to call method of founded callback class |
||
160 | if (method_exists($callClass, $callMethod)) { |
||
161 | $actionQuery = []; |
||
162 | // prepare action params for callback |
||
163 | if (!Str::likeEmpty(self::$Request->getID())) { |
||
164 | $actionQuery[] = self::$Request->getID(); |
||
165 | if (!Str::likeEmpty(self::$Request->getAdd())) { |
||
166 | $actionQuery[] = self::$Request->getAdd(); |
||
167 | } |
||
168 | } |
||
169 | // make callback call to action in controller and get response |
||
170 | $actionResponse = @call_user_func_array([$callClass, $callMethod], $actionQuery); |
||
171 | if ($actionResponse !== null && !Str::likeEmpty($actionResponse)) { |
||
172 | // set response to controller property object |
||
173 | $callClass->setResponse($actionResponse); |
||
174 | } |
||
175 | |||
176 | $html = $callClass->getOutput(); |
||
177 | } else { |
||
178 | throw new NotFoundException('Method "' . App::$Security->strip_tags($callMethod) . '()" not founded in "' . get_class($callClass) . '"'); |
||
179 | } |
||
180 | } catch (NotFoundException $e) { // catch exceptions and set output |
||
181 | $html = $e->display(); |
||
182 | } catch (ForbiddenException $e) { |
||
183 | $html = $e->display(); |
||
184 | } catch (SyntaxException $e) { |
||
185 | $html = $e->display(); |
||
186 | } catch (JsonException $e) { |
||
187 | $html = $e->display(); |
||
188 | } catch (NativeException $e) { |
||
189 | $html = $e->display(); |
||
190 | } catch (\Exception $e) { // catch all other exceptions |
||
191 | $html = (new NativeException($e->getMessage()))->display(); |
||
192 | } |
||
193 | |||
194 | // set full rendered content to response builder |
||
195 | self::$Response->setContent($html); |
||
196 | // echo full response to user via http foundation |
||
197 | self::$Response->send(); |
||
198 | } |
||
199 | |||
200 | } |