| Conditions | 4 |
| Paths | 6 |
| Total Lines | 77 |
| Code Lines | 55 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
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 |
||
| 64 | public function profile() |
||
| 65 | { |
||
| 66 | $user = $_SESSION['phpci_user']; |
||
| 67 | |||
| 68 | if ($this->request->getMethod() == 'POST') { |
||
| 69 | $name = $this->getParam('name', null); |
||
| 70 | $email = $this->getParam('email', null); |
||
| 71 | $password = $this->getParam('password', null); |
||
| 72 | |||
| 73 | $currentLang = Lang::getLanguage(); |
||
| 74 | $chosenLang = $this->getParam('language', $currentLang); |
||
| 75 | |||
| 76 | if ($chosenLang !== $currentLang) { |
||
| 77 | setcookie('phpcilang', $chosenLang, time() + (10 * 365 * 24 * 60 * 60), '/'); |
||
| 78 | Lang::setLanguage($chosenLang); |
||
| 79 | } |
||
| 80 | |||
| 81 | $_SESSION['phpci_user'] = $this->userService->updateUser($user, $name, $email, $password); |
||
| 82 | $user = $_SESSION['phpci_user']; |
||
| 83 | |||
| 84 | $this->view->updated = 1; |
||
| 85 | } |
||
| 86 | |||
| 87 | $this->layout->title = $user->getName(); |
||
| 88 | $this->layout->subtitle = Lang::get('edit_profile'); |
||
| 89 | |||
| 90 | $values = $user->getDataArray(); |
||
| 91 | |||
| 92 | if (array_key_exists('phpcilang', $_COOKIE)) { |
||
| 93 | $values['language'] = $_COOKIE['phpcilang']; |
||
| 94 | } |
||
| 95 | |||
| 96 | $form = new Form(); |
||
| 97 | $form->setAction(PHPCI_URL.'user/profile'); |
||
| 98 | $form->setMethod('POST'); |
||
| 99 | |||
| 100 | $name = new Form\Element\Text('name'); |
||
| 101 | $name->setClass('form-control'); |
||
| 102 | $name->setContainerClass('form-group'); |
||
| 103 | $name->setLabel(Lang::get('name')); |
||
| 104 | $name->setRequired(true); |
||
| 105 | $form->addField($name); |
||
| 106 | |||
| 107 | $email = new Form\Element\Email('email'); |
||
| 108 | $email->setClass('form-control'); |
||
| 109 | $email->setContainerClass('form-group'); |
||
| 110 | $email->setLabel(Lang::get('email_address')); |
||
| 111 | $email->setRequired(true); |
||
| 112 | $form->addField($email); |
||
| 113 | |||
| 114 | $password = new Form\Element\Password('password'); |
||
| 115 | $password->setClass('form-control'); |
||
| 116 | $password->setContainerClass('form-group'); |
||
| 117 | $password->setLabel(Lang::get('password_change')); |
||
| 118 | $password->setRequired(false); |
||
| 119 | $form->addField($password); |
||
| 120 | |||
| 121 | $lang = new Form\Element\Select('language'); |
||
| 122 | $lang->setClass('form-control'); |
||
| 123 | $lang->setContainerClass('form-group'); |
||
| 124 | $lang->setLabel(Lang::get('language')); |
||
| 125 | $lang->setRequired(true); |
||
| 126 | $lang->setOptions(Lang::getLanguageOptions()); |
||
| 127 | $lang->setValue(Lang::getLanguage()); |
||
| 128 | $form->addField($lang); |
||
| 129 | |||
| 130 | $submit = new Form\Element\Submit(); |
||
| 131 | $submit->setClass('btn btn-success'); |
||
| 132 | $submit->setValue(Lang::get('save')); |
||
| 133 | $form->addField($submit); |
||
| 134 | |||
| 135 | $form->setValues($values); |
||
| 136 | |||
| 137 | $this->view->form = $form; |
||
| 138 | |||
| 139 | return $this->view->render(); |
||
| 140 | } |
||
| 141 | |||
| 301 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.