| Conditions | 14 | 
| Paths | 10 | 
| Total Lines | 27 | 
| 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 | ||
| 25 | public function match($body) | ||
| 26 |     { | ||
| 27 | $hasFormData = false; | ||
| 28 |         foreach ($this->structure as $parameter) { | ||
| 29 |             if ($parameter['in'] === "body") { | ||
| 30 |                 if (isset($parameter['required']) && $parameter['required'] === true && empty($body)) { | ||
| 31 |                     throw new RequiredArgumentNotFound('The body is required but it is empty'); | ||
| 32 | } | ||
| 33 | return $this->matchSchema($this->name, $parameter['schema'], $body); | ||
| 34 | } | ||
| 35 |             if ($parameter['in'] === "formData") { | ||
| 36 | $hasFormData = true; | ||
| 37 |                 if (isset($parameter['required']) && $parameter['required'] === true && !isset($body[$parameter['name']])) { | ||
| 38 |                     throw new RequiredArgumentNotFound("The formData parameter '${parameter['name']}' is required but it isn't found. "); | ||
| 39 | } | ||
| 40 |                 if (!$this->matchTypes($parameter['name'], $parameter, (isset($body[$parameter['name']]) ? $body[$parameter['name']] : null))) { | ||
| 41 |                     throw new NotMatchedException("The formData parameter '${parameter['name']}' not match with the specification"); | ||
| 42 | } | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 |         if (!empty($body) && !$hasFormData) { | ||
| 47 |             throw new InvalidDefinitionException('Body is passed but there is no request body definition'); | ||
| 48 | } | ||
| 49 | |||
| 50 | return false; | ||
| 51 | } | ||
| 52 | } | ||
| 53 |