| Conditions | 9 |
| Paths | 9 |
| Total Lines | 54 |
| 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 |
||
| 72 | private function checkResponseCode($responseCode, \ArrayIterator $recipients) |
||
| 73 | { |
||
| 74 | switch ($responseCode) { |
||
| 75 | case self::REQUEST_HAS_SUCCEED_CODE: |
||
| 76 | break; |
||
| 77 | |||
| 78 | case self::MALFORMED_NOTIFICATION_CODE: |
||
| 79 | throw new MalformedNotificationException( |
||
| 80 | "Notification request with a bad XML document or malformed notification URI" |
||
| 81 | ); |
||
| 82 | |||
| 83 | case self::AUTHENTICATION_ERROR_CODE: |
||
| 84 | throw new DispatchMessageException( |
||
| 85 | "Sending this notification is unauthorized", self::AUTHENTICATION_ERROR_CODE |
||
| 86 | ); |
||
| 87 | |||
| 88 | case self::INVALID_RECIPIENT_ERROR_CODE: |
||
| 89 | $recipients->current()->setIdentifierStatus(RecipientDevice::DEVICE_NOT_REGISTERED); |
||
| 90 | |||
| 91 | throw new InvalidRecipientException( |
||
| 92 | "The subscription is invalid and is not present on the Push Notification Service", |
||
| 93 | $recipients |
||
| 94 | ); |
||
| 95 | |||
| 96 | case self::INVALID_METHOD_ERROR_CODE: |
||
| 97 | throw new DispatchMessageException( |
||
| 98 | "Invalid method. Only POST is allowed when sending a notification request", |
||
| 99 | self::INVALID_METHOD_ERROR_CODE |
||
| 100 | ); |
||
| 101 | |||
| 102 | case self::QUOTA_EXCEEDED_ERROR_CODE: |
||
| 103 | throw new DispatchMessageException( |
||
| 104 | "Unauthenticated service has reached the per-day throttling limit or there are many notifications per second", |
||
| 105 | self::QUOTA_EXCEEDED_ERROR_CODE |
||
| 106 | ); |
||
| 107 | |||
| 108 | case self::DEVICE_INACTIVE_ERROR_CODE: |
||
| 109 | throw new DispatchMessageException( |
||
| 110 | "The device is in a disconnected state", |
||
| 111 | self::DEVICE_INACTIVE_ERROR_CODE |
||
| 112 | ); |
||
| 113 | |||
| 114 | case self::SERVER_UNAVAILABLE_ERROR_CODE: |
||
| 115 | throw new DispatchMessageException( |
||
| 116 | "The Push Notification Service is unable to process the request", |
||
| 117 | self::SERVER_UNAVAILABLE_ERROR_CODE |
||
| 118 | ); |
||
| 119 | |||
| 120 | default: |
||
| 121 | throw new RuntimeException( |
||
| 122 | "Unknown error occurred while sending notification." |
||
| 123 | ); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | } |
||
| 127 |