| Conditions | 10 |
| Paths | 24 |
| Total Lines | 37 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | 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 |
||
| 43 | public function getAddressFromZipcode($zipCode) |
||
| 44 | { |
||
| 45 | $found = false; |
||
| 46 | |||
| 47 | shuffle($this->listApi); |
||
| 48 | |||
| 49 | foreach ($this->listApi as $api) { |
||
| 50 | if (!$found) { |
||
| 51 | switch ($api) { |
||
| 52 | case 'ViaCep': |
||
| 53 | $found = $this->getFromViaCep($zipCode); |
||
| 54 | break; |
||
| 55 | |||
| 56 | case 'WebMania': |
||
| 57 | $found = $this->getFromWebMania($zipCode); |
||
| 58 | break; |
||
| 59 | |||
| 60 | case 'WideNet': |
||
| 61 | $found = $this->getFromWideNet($zipCode); |
||
| 62 | break; |
||
| 63 | |||
| 64 | case 'CepLa': |
||
| 65 | $found = $this->getFromCepLa($zipCode); |
||
| 66 | break; |
||
| 67 | } |
||
| 68 | |||
| 69 | if (!isset($found['address']) || !$found['status']) { |
||
| 70 | $found = false; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | if (!$found) { |
||
| 76 | throw new ZipCodeNotFoundException("Error to get address by zipcode: {$zipCode}"); |
||
| 77 | } |
||
| 78 | |||
| 79 | return $found; |
||
| 80 | } |
||
| 114 |