Conditions | 14 |
Paths | 51 |
Total Lines | 59 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 9 | ||
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 | if (!isset($this->operationObject->getDefinition()->parameters)) { |
||
82 | return new \stdClass; |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * TODO Hack |
||
87 | * @see https://github.com/kleijnweb/swagger-bundle/issues/24 |
||
88 | */ |
||
89 | $content = null; |
||
90 | if ($request->getContent()) { |
||
91 | $content = json_decode($request->getContent()); |
||
92 | //TODO UT this |
||
93 | $content = (is_array($content) && isset($content[0])) ? $content : (object)$content; |
||
94 | } |
||
95 | |||
96 | $parameters = new \stdClass; |
||
97 | |||
98 | $paramBagMapping = [ |
||
99 | 'query' => 'query', |
||
100 | 'path' => 'attributes', |
||
101 | 'body' => 'attributes', |
||
102 | 'header' => 'headers' |
||
103 | ]; |
||
104 | foreach ($this->operationObject->getDefinition()->parameters as $paramDefinition) { |
||
105 | $paramName = $paramDefinition->name; |
||
106 | |||
107 | if (!isset($paramBagMapping[$paramDefinition->in])) { |
||
108 | throw new UnsupportedException( |
||
109 | "Unsupported parameter 'in' value in definition '{$paramDefinition->in}'" |
||
110 | ); |
||
111 | } |
||
112 | if (!$request->attributes->has($paramName)) { |
||
113 | continue; |
||
114 | } |
||
115 | if ($paramDefinition->in === 'body' && $content !== null) { |
||
116 | $parameters->$paramName = $content; |
||
117 | continue; |
||
118 | } |
||
119 | $parameters->$paramName = $request->attributes->get($paramName); |
||
120 | |||
121 | /** |
||
122 | * If value already coerced into \DateTime object, use any non-empty value for validation |
||
123 | */ |
||
124 | if ($parameters->$paramName instanceof \DateTime) { |
||
125 | if (isset($paramDefinition->format)) { |
||
126 | if ($paramDefinition->format === 'date') { |
||
127 | $parameters->$paramName = '1970-01-01'; |
||
128 | } |
||
129 | if ($paramDefinition->format === 'date-time') { |
||
130 | $parameters->$paramName = '1970-01-01T00:00:00Z'; |
||
131 | } |
||
132 | } |
||
133 | } |
||
134 | } |
||
135 | |||
136 | return $parameters; |
||
137 | } |
||
138 | } |
||
139 |