| Conditions | 10 |
| Paths | 7 |
| Total Lines | 37 |
| Code Lines | 21 |
| 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 |
||
| 70 | protected function doApproveAction() |
||
| 71 | { |
||
| 72 | if (! $this->hasAuthenticatedUser() || ! $this->getAcl()->isUserAllowed($this->getAuthenticatedUser(), 'Donor', 'approve')) { |
||
| 73 | return; |
||
| 74 | } |
||
| 75 | |||
| 76 | $actionToken = filter_input(INPUT_POST, 'token'); |
||
| 77 | $sessionToken = $this->getSession()->getCsrfToken(); |
||
| 78 | |||
| 79 | if (! $actionToken || ! $sessionToken->isValid($actionToken)) { |
||
| 80 | return; |
||
| 81 | } |
||
| 82 | |||
| 83 | $donors = $this->donors; |
||
| 84 | |||
| 85 | if (! $donors || ! is_array($donors)) { |
||
|
|
|||
| 86 | return; |
||
| 87 | } |
||
| 88 | |||
| 89 | $approvedDonorsCount = 0; |
||
| 90 | |||
| 91 | foreach ($donors as $donor) { |
||
| 92 | if (! $donor->isPending()) { |
||
| 93 | continue; |
||
| 94 | } |
||
| 95 | if ($this->getAcl()->canApproveDonor($this->getAuthenticatedUser(), $donor)) { |
||
| 96 | $donor->set('status', 'approved'); |
||
| 97 | $approvedDonorsCount++; |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | $this->getEntityManager()->flush(); |
||
| 102 | |||
| 103 | EBB\redirect( |
||
| 104 | EBB\addQueryArgs( |
||
| 105 | EBB\getEditDonorsURL(), |
||
| 106 | ['flag-approved' => $approvedDonorsCount] |
||
| 107 | ) |
||
| 111 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.