| Conditions | 13 |
| Paths | 40 |
| Total Lines | 58 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 44 | public function findNotificationRegistrations( |
||
| 45 | Event $event, |
||
| 46 | CustomNotification $customNotification, |
||
| 47 | array $findConstraints = [] |
||
| 48 | ) { |
||
| 49 | $constraints = []; |
||
| 50 | $query = $this->createQuery(); |
||
| 51 | $constraints[] = $query->equals('event', $event); |
||
| 52 | $constraints[] = $query->equals('ignoreNotifications', false); |
||
| 53 | |||
| 54 | switch ($customNotification->getRecipients()) { |
||
| 55 | case CustomNotification::RECIPIENTS_CONFIRMED: |
||
| 56 | $constraints[] = $query->equals('confirmed', true); |
||
| 57 | $constraints[] = $query->equals('waitlist', false); |
||
| 58 | break; |
||
| 59 | case CustomNotification::RECIPIENTS_UNCONFIRMED: |
||
| 60 | $constraints[] = $query->equals('confirmed', false); |
||
| 61 | $constraints[] = $query->equals('waitlist', false); |
||
| 62 | break; |
||
| 63 | case CustomNotification::RECIPIENTS_WAITLIST_CONFIRMED: |
||
| 64 | $constraints[] = $query->equals('confirmed', true); |
||
| 65 | $constraints[] = $query->equals('waitlist', true); |
||
| 66 | break; |
||
| 67 | case CustomNotification::RECIPIENTS_WAITLIST_UNCONFIRMED: |
||
| 68 | $constraints[] = $query->equals('confirmed', false); |
||
| 69 | $constraints[] = $query->equals('waitlist', true); |
||
| 70 | break; |
||
| 71 | default: |
||
| 72 | } |
||
| 73 | |||
| 74 | if (!is_array($findConstraints) || count($findConstraints) === 0) { |
||
|
|
|||
| 75 | return $query->matching($query->logicalAnd($constraints))->execute(); |
||
| 76 | } |
||
| 77 | |||
| 78 | foreach ($findConstraints as $findConstraint => $value) { |
||
| 79 | $condition = key($value); |
||
| 80 | switch ($condition) { |
||
| 81 | case 'equals': |
||
| 82 | $constraints[] = $query->equals($findConstraint, $value[$condition]); |
||
| 83 | break; |
||
| 84 | case 'lessThan': |
||
| 85 | $constraints[] = $query->lessThan($findConstraint, $value[$condition]); |
||
| 86 | break; |
||
| 87 | case 'lessThanOrEqual': |
||
| 88 | $constraints[] = $query->lessThanOrEqual($findConstraint, $value[$condition]); |
||
| 89 | break; |
||
| 90 | case 'greaterThan': |
||
| 91 | $constraints[] = $query->greaterThan($findConstraint, $value[$condition]); |
||
| 92 | break; |
||
| 93 | case 'greaterThanOrEqual': |
||
| 94 | $constraints[] = $query->greaterThanOrEqual($findConstraint, $value[$condition]); |
||
| 95 | break; |
||
| 96 | default: |
||
| 97 | throw new \InvalidArgumentException('An error occured - Unknown condition: ' . $condition); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | return $query->matching($query->logicalAnd($constraints))->execute(); |
||
| 102 | } |
||
| 229 |