Conditions | 19 |
Paths | 32 |
Total Lines | 69 |
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 |
||
143 | public function build(array $parameters) |
||
144 | { |
||
145 | foreach ($parameters as $property => $value) { |
||
146 | switch ($property) { |
||
147 | case 'networks': |
||
148 | if (is_object($value)) { |
||
149 | if (property_exists($value, 'v4')) { |
||
150 | foreach ($value->v4 as $subProperty => $subValue) { |
||
151 | $subValue->version = 4; |
||
152 | $this->networks[] = new Network($subValue); |
||
153 | } |
||
154 | } |
||
155 | |||
156 | if (property_exists($value, 'v6')) { |
||
157 | foreach ($value->v6 as $subProperty => $subValue) { |
||
158 | $subValue->version = 6; |
||
159 | $subValue->cidr = $subValue->netmask; |
||
160 | $subValue->netmask = null; |
||
161 | $this->networks[] = new Network($subValue); |
||
162 | } |
||
163 | } |
||
164 | } |
||
165 | unset($parameters[$property]); |
||
166 | break; |
||
167 | |||
168 | case 'kernel': |
||
169 | if (is_object($value)) { |
||
170 | $this->kernel = new Kernel($value); |
||
171 | } |
||
172 | unset($parameters[$property]); |
||
173 | break; |
||
174 | |||
175 | case 'size': |
||
176 | if (is_object($value)) { |
||
177 | $this->size = new Size($value); |
||
178 | } |
||
179 | unset($parameters[$property]); |
||
180 | break; |
||
181 | |||
182 | case 'region': |
||
183 | if (is_object($value)) { |
||
184 | $this->region = new Region($value); |
||
185 | } |
||
186 | unset($parameters[$property]); |
||
187 | break; |
||
188 | |||
189 | case 'image': |
||
190 | if (is_object($value)) { |
||
191 | $this->image = new Image($value); |
||
192 | } |
||
193 | unset($parameters[$property]); |
||
194 | break; |
||
195 | |||
196 | case 'next_backup_window': |
||
197 | $this->nextBackupWindow = new NextBackupWindow($value); |
||
198 | unset($parameters[$property]); |
||
199 | break; |
||
200 | } |
||
201 | } |
||
202 | |||
203 | parent::build($parameters); |
||
204 | |||
205 | if (is_array($this->features) && count($this->features)) { |
||
206 | $this->backupsEnabled = in_array('backups', $this->features); |
||
207 | $this->virtIOEnabled = in_array('virtio', $this->features); |
||
208 | $this->privateNetworkingEnabled = in_array('private_networking', $this->features); |
||
209 | $this->ipv6Enabled = in_array('ipv6', $this->features); |
||
210 | } |
||
211 | } |
||
212 | |||
221 |