| Conditions | 10 |
| Paths | 7 |
| Total Lines | 31 |
| 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 |
||
| 109 | { |
||
| 110 | try { |
||
| 111 | $content = \json_decode((string) $request->getContent(), true, 512, \JSON_THROW_ON_ERROR); |
||
| 112 | } catch (\JsonException $e) { |
||
| 113 | throw new BadRequestHttpException('Invalid JSON.'); |
||
| 114 | } catch (\Exception $e) { |
||
| 115 | throw $e; |
||
| 116 | } |
||
| 117 | |||
| 118 | $result = []; |
||
| 119 | |||
| 120 | if (!isset($content['client']) || !\is_string($content['client'])) { |
||
| 121 | throw new BadRequestHttpException('Client must be set in request.'); |
||
| 122 | } |
||
| 123 | $result[] = $content['client']; |
||
| 124 | |||
| 125 | if (!isset($content['channels']) || !\is_array($content['channels']) || empty($content['channels'])) { |
||
| 126 | throw new BadRequestHttpException('Channels must be set in request.'); |
||
| 127 | } |
||
| 128 | |||
| 129 | foreach ($content['channels'] as $channel) { |
||
| 130 | if (!\is_string($channel)) { |
||
| 131 | throw new BadRequestHttpException('Channel must be a string.'); |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | $result[] = $content['channels']; |
||
| 136 | |||
| 137 | return $result; |
||
| 138 | } |
||
| 139 | } |
||
| 140 |