Conditions | 8 |
Paths | 25 |
Total Lines | 64 |
Code Lines | 28 |
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 |
||
111 | protected function doSubmitAction() |
||
112 | { |
||
113 | try { |
||
114 | $sessionToken = $this->getSession()->getCsrfToken(); |
||
115 | $actionToken = filter_input(INPUT_POST, 'token'); |
||
116 | |||
117 | if (! $actionToken || ! $sessionToken->isValid($actionToken)) { |
||
118 | return; |
||
119 | } |
||
120 | |||
121 | $donor = $this->donor; |
||
122 | |||
123 | if (! $this->hasAuthenticatedUser() || ! $this->getAcl()->canEditEntity($this->getAuthenticatedUser(), $donor)) { |
||
124 | return; |
||
125 | } |
||
126 | |||
127 | // Set the donor name. |
||
128 | $donor->set('name', filter_input(INPUT_POST, 'donor_name'), true); |
||
129 | |||
130 | // Set the donor gender. |
||
131 | $donor->set('gender', filter_input(INPUT_POST, 'donor_gender'), true); |
||
132 | |||
133 | // Set the donor birthdate. |
||
134 | $donor->set('birthdate', filter_input(INPUT_POST, 'donor_birthdate'), true); |
||
135 | |||
136 | // Set the donor blood group. |
||
137 | $donor->set('blood_group', filter_input(INPUT_POST, 'donor_blood_group'), true); |
||
138 | |||
139 | // Set the donor district ID. |
||
140 | $donor->set('district', $this->getDistrictRepository()->find(filter_input(INPUT_POST, 'donor_district_id'))); |
||
141 | |||
142 | // Set the donor weight. |
||
143 | $donor->setMeta('weight', filter_input(INPUT_POST, 'donor_weight'), true); |
||
144 | |||
145 | // Set the donor email address. |
||
146 | $donor->setMeta('email', filter_input(INPUT_POST, 'donor_email'), true); |
||
147 | |||
148 | // Set the donor email address visibility. |
||
149 | $donor->setMeta('email_visibility', filter_input(INPUT_POST, 'donor_email_visibility'), true); |
||
150 | |||
151 | // Set the donor phone number. |
||
152 | $donor->setMeta('phone', filter_input(INPUT_POST, 'donor_phone'), true); |
||
153 | |||
154 | // Set the donor phone number visibility. |
||
155 | $donor->setMeta('phone_visibility', filter_input(INPUT_POST, 'donor_phone_visibility'), true); |
||
156 | |||
157 | // Set the donor address. |
||
158 | $donor->setMeta('address', filter_input(INPUT_POST, 'donor_address'), true); |
||
159 | |||
160 | // Set the donor status. |
||
161 | if ($donor->isApproved() && ! $this->getAcl()->isUserAllowed($this->getAuthenticatedUser(), 'Donor', 'approve')) { |
||
162 | $donor->set('status', 'pending'); |
||
163 | } |
||
164 | |||
165 | $this->getEntityManager()->flush($donor); |
||
166 | |||
167 | EBB\redirect( |
||
168 | EBB\addQueryArgs( |
||
169 | EBB\getEditDonorURL($donor->get('id')), |
||
170 | ['flag-edited' => true] |
||
171 | ) |
||
172 | ); |
||
173 | } catch (InvalidArgumentException $ex) { |
||
174 | Notices::addNotice('invalid_donor_argument', $ex->getMessage()); |
||
175 | } |
||
178 |