Conditions | 11 |
Paths | 40 |
Total Lines | 42 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 10 | ||
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, use any non-empty value for validation |
||
108 | */ |
||
109 | if ($parameters->$paramName instanceof \DateTime) { |
||
110 | if ($paramDefinition->format === 'date') { |
||
111 | $parameters->$paramName = '1970-01-01'; |
||
112 | } |
||
113 | if ($paramDefinition->format === 'date-time') { |
||
114 | $parameters->$paramName = '1970-01-01T00:00:00Z'; |
||
115 | } |
||
116 | } |
||
117 | } |
||
118 | |||
119 | return $parameters; |
||
120 | } |
||
121 | } |
||
122 |