| Conditions | 30 |
| Paths | 30 |
| Total Lines | 106 |
| Code Lines | 64 |
| 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 |
||
| 93 | private function createByReason(string $reason, array $json) |
||
| 94 | { |
||
| 95 | $reason = strtolower($reason); |
||
| 96 | |||
| 97 | switch ($reason) { |
||
| 98 | // Bad request (400) |
||
| 99 | case 'badcollapseid': |
||
| 100 | return new BadCollapseIdException(); |
||
| 101 | |||
| 102 | case 'baddevicetoken': |
||
| 103 | return new BadDeviceTokenException(); |
||
| 104 | |||
| 105 | case 'badexpirationdate': |
||
| 106 | return new BadExpirationDateException(); |
||
| 107 | |||
| 108 | case 'badmessageid': |
||
| 109 | return new BadMessageIdException(); |
||
| 110 | |||
| 111 | case 'badpriority': |
||
| 112 | return new BadPriorityException(); |
||
| 113 | |||
| 114 | case 'badtopic': |
||
| 115 | return new BadTopicException(); |
||
| 116 | |||
| 117 | case 'devicetokennotfortopic': |
||
| 118 | return new DeviceTokenNotForTopicException(); |
||
| 119 | |||
| 120 | case 'duplicateheaders': |
||
| 121 | return new DuplicateHeadersException(); |
||
| 122 | |||
| 123 | case 'idletimeout': |
||
| 124 | return new IdleTimeoutException(); |
||
| 125 | |||
| 126 | case 'missingdevicetoken': |
||
| 127 | return new MissingDeviceTokenException(); |
||
| 128 | |||
| 129 | case 'missingtopic': |
||
| 130 | return new MissingTopicException(); |
||
| 131 | |||
| 132 | case 'payloadempty': |
||
| 133 | return new PayloadEmptyException(); |
||
| 134 | |||
| 135 | case 'topicdisallowed': |
||
| 136 | return new TopicDisallowedException(); |
||
| 137 | |||
| 138 | // Access denied (403) |
||
| 139 | case 'badcertificate': |
||
| 140 | return new BadCertificateException(); |
||
| 141 | |||
| 142 | case 'badcertificateenvironment': |
||
| 143 | return new BadCertificateEnvironmentException(); |
||
| 144 | |||
| 145 | case 'expiredprovidertoken': |
||
| 146 | return new ExpiredProviderTokenException(); |
||
| 147 | |||
| 148 | case 'forbidden': |
||
| 149 | return new ForbiddenException(); |
||
| 150 | |||
| 151 | case 'invalidprovidertoken': |
||
| 152 | return new InvalidProviderTokenException(); |
||
| 153 | |||
| 154 | case 'missingprovidertoken': |
||
| 155 | return new MissingProviderTokenException(); |
||
| 156 | |||
| 157 | // Not found (404) |
||
| 158 | case 'badpath': |
||
| 159 | return new BadPathException(); |
||
| 160 | |||
| 161 | // Method not allowed (405) |
||
| 162 | case 'methodnotallowed': |
||
| 163 | return new MethodNotAllowedException(); |
||
| 164 | |||
| 165 | // Gone (410) |
||
| 166 | case 'unregistered': |
||
| 167 | $timestamp = array_key_exists('timestamp', $json) ? $json['timestamp'] : 0; |
||
| 168 | $lastConfirmed = new \DateTime('now', new \DateTimeZone('UTC')); |
||
| 169 | $lastConfirmed->setTimestamp($timestamp); |
||
| 170 | |||
| 171 | return new UnregisteredException($lastConfirmed); |
||
| 172 | |||
| 173 | // Request entity too large (413) |
||
| 174 | case 'payloadtoolarge': |
||
| 175 | return new PayloadTooLargeException(); |
||
| 176 | |||
| 177 | // Too many requests (429) |
||
| 178 | case 'toomanyprovidertokenupdates': |
||
| 179 | return new TooManyProviderTokenUpdatesException(); |
||
| 180 | |||
| 181 | case 'toomanyrequests': |
||
| 182 | return new TooManyRequestsException(); |
||
| 183 | |||
| 184 | // Internal server error (500) |
||
| 185 | case 'internalservererror': |
||
| 186 | return new InternalServerErrorException(); |
||
| 187 | |||
| 188 | // Service unavailable (503) |
||
| 189 | case 'serviceunavailable': |
||
| 190 | return new ServiceUnavailableException(); |
||
| 191 | |||
| 192 | case 'shutdown': |
||
| 193 | return new ShutdownException(); |
||
| 194 | |||
| 195 | default: |
||
| 196 | return new UndefinedErrorException(); |
||
| 197 | } |
||
| 198 | } |
||
| 199 | } |
||
| 200 |