| Conditions | 14 |
| Paths | 55 |
| Total Lines | 50 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 11 | ||
| Bugs | 1 | Features | 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 |
||
| 79 | private function assembleParameterDataForValidation(Request $request) |
||
| 80 | { |
||
| 81 | /** |
||
| 82 | * TODO Hack |
||
| 83 | * @see https://github.com/kleijnweb/swagger-bundle/issues/24 |
||
| 84 | */ |
||
| 85 | $content = null; |
||
| 86 | if ($request->getContent()) { |
||
| 87 | $content = json_decode($request->getContent()); |
||
| 88 | //TODO UT this |
||
| 89 | $content = (is_array($content) && isset($content[0])) ? $content : (object)$content; |
||
| 90 | } |
||
| 91 | |||
| 92 | $parameters = new \stdClass; |
||
| 93 | |||
| 94 | foreach ($this->operationObject->getDefinition()->parameters as $paramDefinition) { |
||
| 95 | $paramName = $paramDefinition->name; |
||
| 96 | |||
| 97 | if (!$request->attributes->has($paramName)) { |
||
| 98 | continue; |
||
| 99 | } |
||
| 100 | if ($paramDefinition->in === 'body' && $content !== null) { |
||
| 101 | $parameters->$paramName = $content; |
||
| 102 | continue; |
||
| 103 | } |
||
| 104 | $parameters->$paramName = $request->attributes->get($paramName); |
||
| 105 | |||
| 106 | /** |
||
| 107 | * If value already coerced into \DateTime object, get the raw value for validation instead |
||
| 108 | * |
||
| 109 | * TODO Keep raw value of attributes around |
||
| 110 | */ |
||
| 111 | if ($parameters->$paramName instanceof \DateTime) { |
||
| 112 | if ($paramDefinition->in === 'query') { |
||
| 113 | $parameters->$paramName = $request->query->get($paramName); |
||
| 114 | } elseif ($paramDefinition->in === 'header') { |
||
| 115 | $parameters->$paramName = $request->headers->get($paramName); |
||
| 116 | } elseif ($paramDefinition->in === 'path') { |
||
| 117 | if ($paramDefinition->format === 'date') { |
||
| 118 | $parameters->$paramName = $parameters->$paramName->format('Y-m-d'); |
||
| 119 | } |
||
| 120 | if ($paramDefinition->format === 'date-time') { |
||
| 121 | $parameters->$paramName = $parameters->$paramName->format(\DateTime::W3C); |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | return $parameters; |
||
| 128 | } |
||
| 129 | } |
||
| 130 |