| Conditions | 5 | 
| Paths | 13 | 
| Total Lines | 78 | 
| Code Lines | 40 | 
| Lines | 0 | 
| Ratio | 0 % | 
| 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 | ||
| 14 | public function init(AbstractionController $c) | ||
| 15 | 	{ | ||
| 16 | $config = $this->getUserConfig(); | ||
| 17 | |||
| 18 | $_config = ArrayDimension::toUnidimensional($config, "_"); | ||
| 19 | |||
| 20 | $this->setTranslator($c); | ||
| 21 | |||
| 22 | # config constraints | ||
| 23 | |||
| 24 | $components = [ | ||
| 25 | "attributes" => [ | ||
| 26 | "project_name" => [ | ||
| 27 | "required" => true, | ||
| 28 | "type" => "text", | ||
| 29 | "minlength" => 2, | ||
| 30 | "maxlength" => 60 | ||
| 31 | ], | ||
| 32 | ], | ||
| 33 | ]; | ||
| 34 | |||
| 35 | $options = [ | ||
| 36 | "project" => [ | ||
| 37 | "label" => "project -> name" | ||
| 38 | ], | ||
| 39 | ]; | ||
| 40 | |||
| 41 | $form = new Form($components); | ||
| 42 | $form->fill($_config); | ||
| 43 | |||
| 44 | $validator = new FormValidator($form, $options); | ||
| 45 | $validator->validate(); | ||
| 46 | |||
| 47 | $data["validator"] = $validator; | ||
|  | |||
| 48 | |||
| 49 | try | ||
| 50 |         { | ||
| 51 | if (!$validator->isValid()) | ||
| 52 |             { | ||
| 53 | $data["messages"] = $validator->getMessages(); | ||
| 54 |                 throw new \Exception("Module config errros in user.config!", 300); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | catch (\Exception $e) | ||
| 58 |         { | ||
| 59 |             $file = str_replace('\\', '', __CLASS__); | ||
| 60 |             $storage = new \Drone\Exception\Storage("cache/$file.json"); | ||
| 61 | |||
| 62 | # stores the error code | ||
| 63 | if (($errorCode = $storage->store($e)) === false) | ||
| 64 |             { | ||
| 65 | $errors = $storage->getErrors(); | ||
| 66 | |||
| 67 | # if error storing is not possible, handle it (internal app error) | ||
| 68 | //$this->handleErrors($errors, __METHOD__); | ||
| 69 | } | ||
| 70 | |||
| 71 | $data["code"] = $errorCode; | ||
| 72 | $data["message"] = $e->getMessage(); | ||
| 73 | |||
| 74 | $config = include 'config/application.config.php'; | ||
| 75 | $data["dev_mode"] = $config["environment"]["dev_mode"]; | ||
| 76 | |||
| 77 | # stops current controller execution | ||
| 78 | $c->stopExecution(false); | ||
| 79 | |||
| 80 | # loads error view | ||
| 81 | $layoutManager = new Layout(); | ||
| 82 | $layoutManager->setBasePath($c->getBasePath()); | ||
| 83 | |||
| 84 | $layoutManager->setView($this, "validation"); | ||
| 85 | $layoutManager->setParams($data); | ||
| 86 | |||
| 87 | # for AJAX requests! | ||
| 88 | if ($c->isXmlHttpRequest()) | ||
| 89 | $layoutManager->content(); | ||
| 90 | else | ||
| 91 | $layoutManager->fromTemplate($this, 'blank'); | ||
| 92 | } | ||
| 119 | } |