Conditions | 7 |
Paths | 39 |
Total Lines | 74 |
Code Lines | 34 |
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 |
||
81 | protected function doSubmitAction() |
||
82 | { |
||
83 | try { |
||
84 | if (! $this->hasAuthenticatedUser() || ! $this->getAcl()->isUserAllowed($this->getAuthenticatedUser(), 'Donor', 'add')) { |
||
85 | return; |
||
86 | } |
||
87 | |||
88 | $sessionToken = $this->getSession()->getCsrfToken(); |
||
89 | $actionToken = filter_input(INPUT_POST, 'token'); |
||
90 | |||
91 | if (! $actionToken || ! $sessionToken->isValid($actionToken)) { |
||
92 | return; |
||
93 | } |
||
94 | |||
95 | $donor = $this->donor; |
||
96 | |||
97 | // Set the donor name. |
||
98 | $donor->set('name', filter_input(INPUT_POST, 'donor_name'), true); |
||
99 | |||
100 | // Set the donor gender. |
||
101 | $donor->set('gender', filter_input(INPUT_POST, 'donor_gender'), true); |
||
102 | |||
103 | // Set the donor birthdate. |
||
104 | $donor->set('birthdate', filter_input(INPUT_POST, 'donor_birthdate'), true); |
||
105 | |||
106 | // Set the donor blood group. |
||
107 | $donor->set('blood_group', filter_input(INPUT_POST, 'donor_blood_group'), true); |
||
108 | |||
109 | // Set the donor district ID. |
||
110 | $donor->set('district', $this->getDistrictRepository()->find(filter_input(INPUT_POST, 'donor_district_id'))); |
||
111 | |||
112 | // Set the originator user. |
||
113 | $donor->set('created_by', $this->getAuthenticatedUser()); |
||
114 | |||
115 | // Set the donor status. |
||
116 | if ($this->getAcl()->isUserAllowed($this->getAuthenticatedUser(), 'Donor', 'approve')) { |
||
117 | $donor->set('status', 'approved'); |
||
118 | } else { |
||
119 | $donor->set('status', 'pending'); |
||
120 | } |
||
121 | |||
122 | // Set the donor weight. |
||
123 | $donor->setMeta('weight', filter_input(INPUT_POST, 'donor_weight'), true); |
||
124 | |||
125 | // Set the donor email address. |
||
126 | $donor->setMeta('email', filter_input(INPUT_POST, 'donor_email'), true); |
||
127 | |||
128 | // Set the donor email address visibility. |
||
129 | $donor->setMeta('email_visibility', filter_input(INPUT_POST, 'donor_email_visibility'), true); |
||
130 | |||
131 | // Set the donor phone number. |
||
132 | $donor->setMeta('phone', filter_input(INPUT_POST, 'donor_phone'), true); |
||
133 | |||
134 | // Set the donor phone number visibility. |
||
135 | $donor->setMeta('phone_visibility', filter_input(INPUT_POST, 'donor_phone_visibility'), true); |
||
136 | |||
137 | // Set the donor address. |
||
138 | $donor->setMeta('address', filter_input(INPUT_POST, 'donor_address'), true); |
||
139 | |||
140 | $this->getEntityManager()->persist($donor); |
||
141 | $this->getEntityManager()->flush(); |
||
142 | |||
143 | $this->getEventManager()->getEventDispatcher()->dispatch('donor.created', new GenericEvent($donor)); |
||
144 | |||
145 | $added = $donor->isExists(); |
||
146 | |||
147 | EBB\redirect( |
||
|
|||
148 | EBB\addQueryArgs( |
||
149 | EBB\getAddDonorURL(), |
||
150 | ['flag-added' => $added] |
||
151 | ) |
||
152 | ); |
||
153 | } catch (InvalidArgumentException $ex) { |
||
154 | Notices::addNotice('invalid_donor_argument', $ex->getMessage()); |
||
155 | } |
||
158 |