| Conditions | 13 |
| Paths | 13 |
| Total Lines | 35 |
| 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 |
||
| 14 | public static function create(int $statusCode, string $message) |
||
| 15 | { |
||
| 16 | switch ($statusCode) { |
||
| 17 | case 401: |
||
| 18 | if ('Name already Exists' === $message) { |
||
| 19 | throw new SoundNameAlreadyExistsException($statusCode, $message); |
||
| 20 | } |
||
| 21 | |||
| 22 | throw new AuthFailedException($statusCode, $message); |
||
| 23 | case 403: |
||
| 24 | throw new BadAccountException($statusCode, $message); |
||
| 25 | case 404: |
||
| 26 | throw new UnknownMethodException($statusCode, $message); |
||
| 27 | case 405: |
||
| 28 | throw new MethodNotImplementedException($statusCode, $message); |
||
| 29 | case 406: |
||
| 30 | throw new NoDidAvailableForRegionException($statusCode, $message); |
||
| 31 | case 407: |
||
| 32 | if ('DID not exists or not owned' === $message) { |
||
| 33 | throw new DidNotExistsOrNotOwnedException($statusCode, $message); |
||
| 34 | } elseif ('DID already reserved or not tested' === $message) { |
||
| 35 | throw new DidAlreadyReservedException($statusCode, $message); |
||
| 36 | } |
||
| 37 | |||
| 38 | throw new UnknownException($statusCode, $message); |
||
| 39 | case 410: |
||
| 40 | throw new CantUseDidAsDestinationException($statusCode, $message); |
||
| 41 | case 500: |
||
| 42 | throw new MissingArgumentsException($statusCode, $message); |
||
| 43 | case 501: |
||
| 44 | throw new UnknownApiException($statusCode, $message); |
||
| 45 | default: |
||
| 46 | throw new UnknownException(-1, $message); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 61 |