| Conditions | 7 |
| Paths | 39 |
| Total Lines | 106 |
| Code Lines | 47 |
| 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 |
||
| 58 | protected function doSignupAction() |
||
| 59 | { |
||
| 60 | try { |
||
| 61 | $user = new User(); |
||
| 62 | |||
| 63 | // Set the user name. |
||
| 64 | $user->set('name', filter_input(INPUT_POST, 'user_name'), true); |
||
| 65 | |||
| 66 | // Set the user email. |
||
| 67 | $user->set('email', filter_input(INPUT_POST, 'user_email'), true); |
||
| 68 | |||
| 69 | $duplicateUser = $this->getUserRepository()->findOneBy(['email' => $user->get('email'), 'status' => 'any']); |
||
| 70 | |||
| 71 | if (! empty($duplicateUser)) { |
||
| 72 | throw new InvalidArgumentException(__('Please enter another e-mail address.')); |
||
| 73 | } |
||
| 74 | |||
| 75 | $userPass1 = filter_input(INPUT_POST, 'user_pass_1', FILTER_UNSAFE_RAW); |
||
| 76 | $userPass2 = filter_input(INPUT_POST, 'user_pass_2', FILTER_UNSAFE_RAW); |
||
| 77 | |||
| 78 | if (empty($userPass1)) { |
||
| 79 | throw new InvalidArgumentException(__('Please enter your password.')); |
||
| 80 | } |
||
| 81 | |||
| 82 | if (empty($userPass2)) { |
||
| 83 | throw new InvalidArgumentException(__('Please confirm your password.')); |
||
| 84 | } |
||
| 85 | |||
| 86 | if ($userPass1 !== $userPass2) { |
||
| 87 | throw new InvalidArgumentException(__('Please enter the same password.')); |
||
| 88 | } |
||
| 89 | |||
| 90 | // Set the user password. |
||
| 91 | $user->set('pass', password_hash($userPass1, PASSWORD_BCRYPT), false); |
||
| 92 | |||
| 93 | // Set the user role. |
||
| 94 | $user->set('role', Options::getOption('new_user_role'), true); |
||
| 95 | |||
| 96 | // Set the user status. |
||
| 97 | $user->set('status', Options::getOption('new_user_status'), true); |
||
| 98 | |||
| 99 | $this->getEntityManager()->persist($user); |
||
| 100 | $this->getEntityManager()->flush(); |
||
| 101 | |||
| 102 | $signedup = $user->isExists(); |
||
| 103 | |||
| 104 | $this->getEventManager()->getEventDispatcher()->dispatch('user.created', new GenericEvent($user)); |
||
| 105 | |||
| 106 | $addDonor = filter_input(INPUT_POST, 'add_as_a_donor'); |
||
| 107 | |||
| 108 | if ($addDonor) { |
||
| 109 | $donor = new Donor(); |
||
| 110 | |||
| 111 | // Set the donor name. |
||
| 112 | $donor->set('name', filter_input(INPUT_POST, 'user_name'), true); |
||
| 113 | |||
| 114 | // Set the donor gender. |
||
| 115 | $donor->set('gender', filter_input(INPUT_POST, 'donor_gender'), true); |
||
| 116 | |||
| 117 | // Set the donor birthdate. |
||
| 118 | $donor->set('birthdate', filter_input(INPUT_POST, 'donor_birthdate'), true); |
||
| 119 | |||
| 120 | // Set the donor blood group. |
||
| 121 | $donor->set('blood_group', filter_input(INPUT_POST, 'donor_blood_group'), true); |
||
| 122 | |||
| 123 | // Set the donor district ID. |
||
| 124 | $donor->set('district', $this->getDistrictRepository()->find(filter_input(INPUT_POST, 'donor_district_id'))); |
||
| 125 | |||
| 126 | // Set the originator user. |
||
| 127 | $donor->set('created_by', $user); |
||
| 128 | |||
| 129 | // Set the donor status. |
||
| 130 | $donor->set('status', 'pending'); |
||
| 131 | |||
| 132 | // Set the donor weight. |
||
| 133 | $donor->setMeta('weight', filter_input(INPUT_POST, 'donor_weight'), true); |
||
| 134 | |||
| 135 | // Set the donor email address. |
||
| 136 | $donor->setMeta('email', filter_input(INPUT_POST, 'user_email'), true); |
||
| 137 | |||
| 138 | // Set the donor email address visibility. |
||
| 139 | $donor->setMeta('email_visibility', Options::getOption('default_donor_email_visibility'), true); |
||
| 140 | |||
| 141 | // Set the donor phone number. |
||
| 142 | $donor->setMeta('phone', filter_input(INPUT_POST, 'donor_phone'), true); |
||
| 143 | |||
| 144 | // Set the donor phone number visibility. |
||
| 145 | $donor->setMeta('phone_visibility', Options::getOption('default_donor_phone_visibility'), true); |
||
| 146 | |||
| 147 | // Set the donor address. |
||
| 148 | $donor->setMeta('address', filter_input(INPUT_POST, 'donor_address'), true); |
||
| 149 | |||
| 150 | $this->getEntityManager()->persist($donor); |
||
| 151 | $this->getEntityManager()->flush(); |
||
| 152 | |||
| 153 | $this->getEventManager()->getEventDispatcher()->dispatch('donor.created', new GenericEvent($donor)); |
||
| 154 | } |
||
| 155 | |||
| 156 | EBB\redirect( |
||
|
|
|||
| 157 | EBB\addQueryArgs( |
||
| 158 | EBB\getLoginURL(), |
||
| 159 | ['flag-signedup' => $signedup] |
||
| 160 | ) |
||
| 161 | ); |
||
| 162 | } catch (InvalidArgumentException $ex) { |
||
| 163 | Notices::addNotice('invalid_user_argument', $ex->getMessage()); |
||
| 164 | } |
||
| 167 |