| 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 | private function processRequest(Request $request): array |
||
| 110 | { |
||
| 111 | try { |
||
| 112 | $content = \json_decode((string) $request->getContent(), true, 512, \JSON_THROW_ON_ERROR); |
||
| 113 | } catch (\JsonException $e) { |
||
| 114 | throw new BadRequestHttpException('Invalid JSON.'); |
||
| 115 | } catch (\Exception $e) { |
||
| 116 | throw $e; |
||
| 117 | } |
||
| 118 | |||
| 119 | $result = []; |
||
| 120 | |||
| 121 | if (!isset($content['client']) || !\is_string($content['client'])) { |
||
| 122 | throw new BadRequestHttpException('Client must be set in request.'); |
||
| 123 | } |
||
| 124 | $result[] = $content['client']; |
||
| 125 | |||
| 126 | if (!isset($content['channels']) || !\is_array($content['channels']) || empty($content['channels'])) { |
||
| 127 | throw new BadRequestHttpException('Channels must be set in request.'); |
||
| 128 | } |
||
| 129 | |||
| 130 | foreach ($content['channels'] as $channel) { |
||
| 131 | if (!\is_string($channel)) { |
||
| 132 | throw new BadRequestHttpException('Channel must be a string.'); |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 136 | $result[] = $content['channels']; |
||
| 137 | |||
| 138 | return $result; |
||
| 139 | } |
||
| 140 | } |
||
| 141 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.