| Conditions | 10 |
| Paths | 12 |
| Total Lines | 50 |
| 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 |
||
| 54 | public function find($address, $page = 1, $lang = 'A') |
||
| 55 | { |
||
| 56 | $cache = $this->file . preg_replace('/[^a-zA-Z0-9_]/', '_', $address) . '_' . strtolower($lang) . '.data'; |
||
| 57 | |||
| 58 | $this->response = $this->cacheValue($cache); |
||
| 59 | |||
| 60 | if ($this->response == null) { |
||
| 61 | $response = $this->_get( |
||
| 62 | 'v4/Address/address-free-text', |
||
| 63 | $lang, |
||
| 64 | [ |
||
| 65 | 'addressstring' => $address, |
||
| 66 | 'page' => $page, |
||
| 67 | ], |
||
| 68 | false |
||
| 69 | ); |
||
| 70 | if ($response['success'] == false) { |
||
| 71 | return; |
||
| 72 | } |
||
| 73 | $addresses = $response['Addresses']; |
||
| 74 | $pages = (int) ceil($response['totalSearchResults'] / 20); |
||
| 75 | if ($page == 1 && ($pages > 1)) { |
||
| 76 | for ($i = 2; $i <= $pages; $i++) { |
||
| 77 | // 1 call allowed per 5 seconds (on Development subscription) |
||
| 78 | ($this->config->getApiSubscription() == 'Development') ? sleep(5) : ''; |
||
| 79 | $pageData = $this->_get( |
||
| 80 | 'v4/Address/address-free-text', |
||
| 81 | $lang, |
||
| 82 | [ |
||
| 83 | 'addressstring' => $address, |
||
| 84 | 'page' => $i, |
||
| 85 | ], |
||
| 86 | false |
||
| 87 | ); |
||
| 88 | $pageData = $pageData['Addresses']; |
||
| 89 | $pageData = array_combine(range(($i * 10), count($pageData) + (($i * 10) - 1)), array_values($pageData)); |
||
| 90 | $addresses += $pageData; |
||
| 91 | } |
||
| 92 | } |
||
| 93 | if($this->config->getCache()){ |
||
| 94 | (!file_exists($this->cacheDir)) ? |
||
| 95 | mkdir($this->cacheDir, 0777, false) : ((file_exists($cache)) ? unlink($cache) : touch($cache)); |
||
| 96 | file_put_contents($cache, serialize($addresses)); |
||
| 97 | } |
||
| 98 | $this->response = $addresses; |
||
| 99 | |||
| 100 | } |
||
| 101 | |||
| 102 | return $this; |
||
| 103 | } |
||
| 104 | |||
| 164 |