Conditions | 11 |
Paths | 41 |
Total Lines | 53 |
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 static function queryRegion($ak, $bucket) |
||
144 | { |
||
145 | $Region = new Region(); |
||
146 | $url = Config::API_HOST . '/v2/query' . "?ak=$ak&bucket=$bucket"; |
||
147 | $ret = Client::Get($url); |
||
148 | if (!$ret->ok()) { |
||
149 | return array(null, new Error($url, $ret)); |
||
150 | } |
||
151 | $r = ($ret->body === null) ? array() : $ret->json(); |
||
152 | //parse Region; |
||
153 | |||
154 | $iovipHost = $r['io']['src']['main'][0]; |
||
155 | $Region->iovipHost = $iovipHost; |
||
156 | $accMain = $r['up']['acc']['main'][0]; |
||
157 | array_push($Region->cdnUpHosts, $accMain); |
||
158 | if (isset($r['up']['acc']['backup'])) { |
||
159 | foreach ($r['up']['acc']['backup'] as $key => $value) { |
||
160 | array_push($Region->cdnUpHosts, $value); |
||
161 | } |
||
162 | } |
||
163 | $srcMain = $r['up']['src']['main'][0]; |
||
164 | array_push($Region->srcUpHosts, $srcMain); |
||
165 | if (isset($r['up']['src']['backup'])) { |
||
166 | foreach ($r['up']['src']['backup'] as $key => $value) { |
||
167 | array_push($Region->srcUpHosts, $value); |
||
168 | } |
||
169 | } |
||
170 | |||
171 | //set specific hosts |
||
172 | if (strstr($Region->iovipHost, "z1") !== false) { |
||
173 | $Region->rsHost = "rs-z1.qbox.me"; |
||
174 | $Region->rsfHost = "rsf-z1.qbox.me"; |
||
175 | $Region->apiHost = "api-z1.qiniu.com"; |
||
176 | } elseif (strstr($Region->iovipHost, "z2") !== false) { |
||
177 | $Region->rsHost = "rs-z2.qbox.me"; |
||
178 | $Region->rsfHost = "rsf-z2.qbox.me"; |
||
179 | $Region->apiHost = "api-z2.qiniu.com"; |
||
180 | } elseif (strstr($Region->iovipHost, "na0") !== false) { |
||
181 | $Region->rsHost = "rs-na0.qbox.me"; |
||
182 | $Region->rsfHost = "rsf-na0.qbox.me"; |
||
183 | $Region->apiHost = "api-na0.qiniu.com"; |
||
184 | } elseif (strstr($Region->iovipHost, "as0") !== false) { |
||
185 | $Region->rsHost = "rs-as0.qbox.me"; |
||
186 | $Region->rsfHost = "rsf-as0.qbox.me"; |
||
187 | $Region->apiHost = "api-as0.qiniu.com"; |
||
188 | } else { |
||
189 | $Region->rsHost = "rs.qbox.me"; |
||
190 | $Region->rsfHost = "rsf.qbox.me"; |
||
191 | $Region->apiHost = "api.qiniu.com"; |
||
192 | } |
||
193 | |||
194 | return $Region; |
||
195 | } |
||
196 | } |
||
197 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: