Conditions | 14 |
Paths | 15 |
Total Lines | 48 |
Code Lines | 31 |
Lines | 19 |
Ratio | 39.58 % |
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 |
||
92 | public function handleCommand($command, $data = null) |
||
93 | { |
||
94 | switch (strtolower($command)) { |
||
95 | // type name description... |
||
96 | case 'property': |
||
97 | case 'property?': |
||
98 | $definition = self::wordShift($data); |
||
99 | if (empty($definition)) { |
||
100 | throw new \SwaggerGen\Exception("Missing property definition"); |
||
101 | } |
||
102 | |||
103 | $name = self::wordShift($data); |
||
104 | if (empty($name)) { |
||
105 | throw new \SwaggerGen\Exception("Missing property name: '{$definition}'"); |
||
106 | } |
||
107 | |||
108 | $this->properties[$name] = new Property($this, $definition, $data); |
||
109 | |||
110 | unset($this->required[$name]); |
||
111 | if (substr($command, -1) !== '?') { |
||
112 | $this->required[$name] = true; |
||
113 | } |
||
114 | return $this; |
||
115 | |||
116 | View Code Duplication | case 'min': |
|
117 | $this->minProperties = intval($data); |
||
118 | if ($this->minProperties < 0) { |
||
119 | throw new \SwaggerGen\Exception("Minimum less than zero: '{$data}'"); |
||
120 | } |
||
121 | if ($this->maxProperties !== null && $this->minProperties > $this->maxProperties) { |
||
122 | throw new \SwaggerGen\Exception("Minimum greater than maximum: '{$data}'"); |
||
123 | } |
||
124 | $this->minProperties = intval($data); |
||
125 | return $this; |
||
126 | |||
127 | View Code Duplication | case 'max': |
|
128 | $this->maxProperties = intval($data); |
||
129 | if ($this->minProperties !== null && $this->minProperties > $this->maxProperties) { |
||
130 | throw new \SwaggerGen\Exception("Maximum less than minimum: '{$data}'"); |
||
131 | } |
||
132 | if ($this->maxProperties < 0) { |
||
133 | throw new \SwaggerGen\Exception("Maximum less than zero: '{$data}'"); |
||
134 | } |
||
135 | return $this; |
||
136 | } |
||
137 | |||
138 | return parent::handleCommand($command, $data); |
||
139 | } |
||
140 | |||
158 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.