Conditions | 25 |
Paths | 45 |
Total Lines | 84 |
Code Lines | 59 |
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 |
||
148 | public function handleCommand($command, $data = null) |
||
149 | { |
||
150 | switch (strtolower($command)) { |
||
151 | // type name description... |
||
152 | case 'additionalproperties': |
||
153 | $value = self::wordShift($data); |
||
154 | if ($value === 'false') { |
||
155 | $type = false; |
||
156 | } else if ($value === 'true') { |
||
157 | $type = true; |
||
158 | } else { |
||
159 | $type = self::typeFactory($this, $value, "Unparseable additional properties definition: '%s'"); |
||
160 | } |
||
161 | $this->setAdditionalProperties($type); |
||
162 | return $this; |
||
163 | case 'discriminator': |
||
164 | $discriminator = self::wordShift($data); |
||
165 | $this->setDiscriminator($discriminator); |
||
166 | return $this; |
||
167 | case 'property': |
||
168 | case 'property?': |
||
169 | case 'property!': |
||
170 | $definition = self::wordShift($data); |
||
171 | if (empty($definition)) { |
||
172 | throw new \SwaggerGen\Exception("Missing property definition"); |
||
173 | } |
||
174 | |||
175 | $name = self::wordShift($data); |
||
176 | if (empty($name)) { |
||
177 | throw new \SwaggerGen\Exception("Missing property name: '{$definition}'"); |
||
178 | } |
||
179 | |||
180 | $readOnly = null; |
||
181 | $required = false; |
||
182 | $propertySuffix = substr($command, -1); |
||
183 | if ($propertySuffix === '!') { |
||
184 | $readOnly = true; |
||
185 | } else if ($propertySuffix !== '?') { |
||
186 | $required = true; |
||
187 | } |
||
188 | |||
189 | if (($name === $this->discriminator) && !$required) { |
||
190 | throw new \SwaggerGen\Exception("Discriminator must be a required property, " |
||
191 | . "property '{$name}' is not required"); |
||
192 | } |
||
193 | |||
194 | unset($this->required[$name]); |
||
195 | if ($required) { |
||
196 | $this->required[$name] = true; |
||
197 | } |
||
198 | |||
199 | $this->mostRecentProperty = new Property($this, $definition, $data, $readOnly); |
||
200 | $this->properties[$name] = $this->mostRecentProperty; |
||
201 | return $this; |
||
202 | |||
203 | case 'min': |
||
204 | $this->minProperties = intval($data); |
||
205 | if ($this->minProperties < 0) { |
||
206 | throw new \SwaggerGen\Exception("Minimum less than zero: '{$data}'"); |
||
207 | } |
||
208 | if ($this->maxProperties !== null && $this->minProperties > $this->maxProperties) { |
||
209 | throw new \SwaggerGen\Exception("Minimum greater than maximum: '{$data}'"); |
||
210 | } |
||
211 | $this->minProperties = intval($data); |
||
212 | return $this; |
||
213 | |||
214 | case 'max': |
||
215 | $this->maxProperties = intval($data); |
||
216 | if ($this->minProperties !== null && $this->minProperties > $this->maxProperties) { |
||
217 | throw new \SwaggerGen\Exception("Maximum less than minimum: '{$data}'"); |
||
218 | } |
||
219 | if ($this->maxProperties < 0) { |
||
220 | throw new \SwaggerGen\Exception("Maximum less than zero: '{$data}'"); |
||
221 | } |
||
222 | return $this; |
||
223 | } |
||
224 | |||
225 | // Pass through to most recent Property |
||
226 | if ($this->mostRecentProperty && $this->mostRecentProperty->handleCommand($command, $data)) { |
||
227 | return $this; |
||
228 | } |
||
229 | |||
230 | return parent::handleCommand($command, $data); |
||
231 | } |
||
232 | |||
252 |
This check looks for the bodies of
if
statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
if
bodies can be removed. If you have an empty if but statements in theelse
branch, consider inverting the condition.could be turned into
This is much more concise to read.