| Conditions | 5 |
| Paths | 13 |
| Total Lines | 168 |
| Code Lines | 104 |
| 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 | "mail_checking_enabled" => [ |
||
| 33 | "required" => true, |
||
| 34 | "type" => "text" |
||
| 35 | ], |
||
| 36 | "mail_checking_from" => [ |
||
| 37 | "required" => false, |
||
| 38 | "type" => "email" |
||
| 39 | ], |
||
| 40 | "authentication_method" => [ |
||
| 41 | "required" => true, |
||
| 42 | "type" => "text" |
||
| 43 | ], |
||
| 44 | "authentication_key" => [ |
||
| 45 | "required" => true, |
||
| 46 | "type" => "text", |
||
| 47 | "minlength" => 1 |
||
| 48 | ], |
||
| 49 | "authentication_type" => [ |
||
| 50 | "required" => true, |
||
| 51 | "type" => "text" |
||
| 52 | ], |
||
| 53 | "authentication_gateway_entity" => [ |
||
| 54 | "required" => false, |
||
| 55 | "type" => "text" |
||
| 56 | ], |
||
| 57 | "authentication_gateway_credentials_username" => [ |
||
| 58 | "required" => false, |
||
| 59 | "type" => "text" |
||
| 60 | ], |
||
| 61 | "authentication_gateway_credentials_password" => [ |
||
| 62 | "required" => false, |
||
| 63 | "type" => "text" |
||
| 64 | ], |
||
| 65 | "authorization_enabled" => [ |
||
| 66 | "required" => true, |
||
| 67 | "type" => "text" |
||
| 68 | ], |
||
| 69 | "database_prefix" => [ |
||
| 70 | "required" => false, |
||
| 71 | "type" => "text" |
||
| 72 | ], |
||
| 73 | "redirect" => [ |
||
| 74 | "required" => true, |
||
| 75 | "type" => "text" |
||
| 76 | ] |
||
| 77 | ], |
||
| 78 | ]; |
||
| 79 | |||
| 80 | $options = [ |
||
| 81 | "project" => [ |
||
| 82 | "label" => "project -> name" |
||
| 83 | ], |
||
| 84 | "mail_checking_enabled" => [ |
||
| 85 | "label" => "mail -> checking -> enabled", |
||
| 86 | "validators" => [ |
||
| 87 | "InArray" => ["haystack" => ['Y', 'N']] |
||
| 88 | ] |
||
| 89 | ], |
||
| 90 | "mail_checking_from" => [ |
||
| 91 | "label" => "mail -> checking -> from" |
||
| 92 | ], |
||
| 93 | "authentication_method" => [ |
||
| 94 | "label" => "authentication -> method", |
||
| 95 | "validators" => [ |
||
| 96 | "InArray" => ["haystack" => ['_COOKIE', '_SESSION']] |
||
| 97 | ] |
||
| 98 | ], |
||
| 99 | "authentication_key" => [ |
||
| 100 | "label" => "authentication -> key", |
||
| 101 | ], |
||
| 102 | "authentication_type" => [ |
||
| 103 | "label" => "authentication -> type", |
||
| 104 | "validators" => [ |
||
| 105 | "InArray" => ["haystack" => ['db_table', 'db_user']] |
||
| 106 | ] |
||
| 107 | ], |
||
| 108 | "authentication_gateway_entity" => [ |
||
| 109 | "label" => "authentication -> gateway -> entity" |
||
| 110 | ], |
||
| 111 | "authentication_gateway_credentials_username" => [ |
||
| 112 | "label" => "authentication -> gateway -> credentials -> username" |
||
| 113 | ], |
||
| 114 | "authentication_gateway_credentials_pasword" => [ |
||
| 115 | "label" => "authentication -> gateway -> credentials -> password" |
||
| 116 | ], |
||
| 117 | "authorization_enabled" => [ |
||
| 118 | "label" => "authorization -> enabled", |
||
| 119 | "validators" => [ |
||
| 120 | "InArray" => ["haystack" => ['Y', 'N']] |
||
| 121 | ] |
||
| 122 | ], |
||
| 123 | "database_prefix" => [ |
||
| 124 | "label" => "database -> prefix" |
||
| 125 | ], |
||
| 126 | "redirect" => [ |
||
| 127 | "label" => "redirect" |
||
| 128 | ], |
||
| 129 | ]; |
||
| 130 | |||
| 131 | $form = new Form($components); |
||
| 132 | $form->fill($_config); |
||
| 133 | |||
| 134 | $validator = new FormValidator($form, $options); |
||
| 135 | $validator->validate(); |
||
| 136 | |||
| 137 | $data["validator"] = $validator; |
||
|
|
|||
| 138 | |||
| 139 | try |
||
| 140 | { |
||
| 141 | if (!$validator->isValid()) |
||
| 142 | { |
||
| 143 | $data["messages"] = $validator->getMessages(); |
||
| 144 | throw new \Exception("Module config errros in user.config!", 300); |
||
| 145 | } |
||
| 146 | } |
||
| 147 | catch (\Exception $e) |
||
| 148 | { |
||
| 149 | $file = str_replace('\\', '', __CLASS__); |
||
| 150 | $storage = new \Drone\Exception\Storage("cache/$file.json"); |
||
| 151 | |||
| 152 | # stores the error code |
||
| 153 | if (($errorCode = $storage->store($e)) === false) |
||
| 154 | { |
||
| 155 | $errors = $storage->getErrors(); |
||
| 156 | |||
| 157 | # if error storing is not possible, handle it (internal app error) |
||
| 158 | //$this->handleErrors($errors, __METHOD__); |
||
| 159 | } |
||
| 160 | |||
| 161 | $data["code"] = $errorCode; |
||
| 162 | $data["message"] = $e->getMessage(); |
||
| 163 | |||
| 164 | $config = include 'config/application.config.php'; |
||
| 165 | $data["dev_mode"] = $config["environment"]["dev_mode"]; |
||
| 166 | |||
| 167 | # stops current controller execution |
||
| 168 | $c->stopExecution(false); |
||
| 169 | |||
| 170 | # loads error view |
||
| 171 | $layoutManager = new Layout(); |
||
| 172 | $layoutManager->setBasePath($c->getBasePath()); |
||
| 173 | |||
| 174 | $layoutManager->setView($this, "validation"); |
||
| 175 | $layoutManager->setParams($data); |
||
| 176 | |||
| 177 | # for AJAX requests! |
||
| 178 | if ($c->isXmlHttpRequest()) |
||
| 179 | $layoutManager->content(); |
||
| 180 | else |
||
| 181 | $layoutManager->fromTemplate($this, 'blank'); |
||
| 182 | } |
||
| 209 | } |