| Conditions | 8 |
| Paths | 6 |
| Total Lines | 91 |
| Code Lines | 54 |
| 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 |
||
| 12 | public function init(AbstractionController $c) |
||
| 13 | { |
||
| 14 | $config = $this->getUserConfig("Auth"); |
||
| 15 | $_config = $this->toFormConfig($config); |
||
| 16 | |||
| 17 | # config constraints |
||
| 18 | |||
| 19 | $components = [ |
||
| 20 | "attributes" => [ |
||
| 21 | "project_name" => [ |
||
| 22 | "required" => true, |
||
| 23 | "type" => "text", |
||
| 24 | "minlength" => 2, |
||
| 25 | "maxlength" => 60 |
||
| 26 | ], |
||
| 27 | "mail_checking_from" => [ |
||
| 28 | "required" => true, |
||
| 29 | "type" => "email" |
||
| 30 | ], |
||
| 31 | "authentication_method" => [ |
||
| 32 | "required" => true, |
||
| 33 | "type" => "text" |
||
| 34 | ], |
||
| 35 | "authentication_key" => [ |
||
| 36 | "required" => true, |
||
| 37 | "type" => "text" |
||
| 38 | ], |
||
| 39 | "redirect" => [ |
||
| 40 | "required" => true, |
||
| 41 | "type" => "text" |
||
| 42 | ] |
||
| 43 | ], |
||
| 44 | ]; |
||
| 45 | |||
| 46 | $options = [ |
||
| 47 | "project" => [ |
||
| 48 | "label" => "project -> name" |
||
| 49 | ], |
||
| 50 | "mail_checking_from" => [ |
||
| 51 | "label" => "mail -> checking -> from" |
||
| 52 | ], |
||
| 53 | "authentication_method" => [ |
||
| 54 | "label" => "authentication -> method", |
||
| 55 | "validators" => [ |
||
| 56 | "InArray" => ["haystack" => ['_COOKIE', '_SESSION']] |
||
| 57 | ] |
||
| 58 | ], |
||
| 59 | "authentication_key" => [ |
||
| 60 | "label" => "authentication -> key", |
||
| 61 | ], |
||
| 62 | "redirect" => [ |
||
| 63 | "label" => "redirect" |
||
| 64 | ], |
||
| 65 | ]; |
||
| 66 | |||
| 67 | $form = new Form($components); |
||
| 68 | $form->fill($_config); |
||
|
|
|||
| 69 | |||
| 70 | $validator = new FormValidator($form, $options); |
||
| 71 | $validator->validate(); |
||
| 72 | |||
| 73 | $data["validator"] = $validator; |
||
| 74 | |||
| 75 | # Validar formulario |
||
| 76 | if (!$validator->isValid()) |
||
| 77 | { |
||
| 78 | $data["messages"] = $validator->getMessages(); |
||
| 79 | throw new \Exception("Module config errros in user.config!", 300); |
||
| 80 | } |
||
| 81 | |||
| 82 | $method = $config["authentication"]["method"]; |
||
| 83 | $key = $config["authentication"]["key"]; |
||
| 84 | |||
| 85 | switch ($method) |
||
| 86 | { |
||
| 87 | case '_COOKIE': |
||
| 88 | |||
| 89 | if (!array_key_exists($key, $_COOKIE) || empty($_COOKIE[$key])) |
||
| 90 | header("location: " . $c->basePath ."/public/". "Auth"); |
||
| 91 | |||
| 92 | break; |
||
| 93 | |||
| 94 | case '_SESSION': |
||
| 95 | |||
| 96 | if (!array_key_exists($key, $_SESSION) || empty($_SESSION[$key])) |
||
| 97 | header("location: " . $c->basePath ."/public/". "Auth"); |
||
| 98 | |||
| 99 | break; |
||
| 100 | } |
||
| 101 | |||
| 102 | $this->setTranslator($c); |
||
| 103 | } |
||
| 151 | } |