Conditions | 13 |
Paths | 36 |
Total Lines | 114 |
Code Lines | 72 |
Lines | 9 |
Ratio | 7.89 % |
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 |
||
132 | function getEpostapiSearch($query = '') |
||
133 | { |
||
134 | /** |
||
135 | * @brief 문자열 인코딩 변환 |
||
136 | * @note 우체국 우편번호 API는 검색어를 EUC-KR로 넘겨주어야 함 |
||
137 | */ |
||
138 | $encoding = strtoupper(mb_detect_encoding($query)); |
||
139 | if($encoding !== 'EUC-KR') |
||
140 | { |
||
141 | $query = iconv($encoding, 'EUC-KR', $query); |
||
142 | } |
||
143 | |||
144 | $module_config = $this->getConfig(); |
||
145 | $regkey = $module_config->epostapi_regkey; |
||
146 | |||
147 | $fields = array( |
||
148 | 'target' => 'postNew', /* 도로명 주소 */ |
||
149 | 'regkey' => $regkey, |
||
150 | 'query' => $query |
||
151 | ); |
||
152 | $headers = array( |
||
153 | 'accept-language' => 'ko' |
||
154 | ); |
||
155 | $request_config = array( |
||
156 | 'ssl_verify_peer' => FALSE |
||
157 | ); |
||
158 | |||
159 | $buff = FileHandler::getRemoteResource( |
||
160 | self::$epostapi_host, |
||
161 | NULL, |
||
162 | 30, |
||
163 | 'POST', |
||
164 | 'application/x-www-form-urlencoded', |
||
165 | $headers, |
||
166 | array(), |
||
167 | $fields, |
||
168 | $request_config |
||
169 | ); |
||
170 | |||
171 | $oXmlParser = new XmlParser(); |
||
172 | $result = $oXmlParser->parse($buff); |
||
173 | if($result->error) |
||
174 | { |
||
175 | $err_msg = trim($result->error->message->body); |
||
176 | if(!$err_msg) |
||
177 | { |
||
178 | $err_code = intval(str_replace('ERR-', '', $result->error->error_code->body)); |
||
179 | switch($err_code) |
||
180 | { |
||
181 | case 1: |
||
182 | $err_msg = 'msg_krzip_is_maintenance'; |
||
183 | break; |
||
184 | case 2: |
||
185 | $err_msg = 'msg_krzip_wrong_regkey'; |
||
186 | break; |
||
187 | case 3: |
||
188 | $err_msg = 'msg_krzip_no_result'; |
||
189 | break; |
||
190 | default: |
||
191 | $err_msg = 'msg_krzip_riddling_wrong'; |
||
192 | break; |
||
193 | } |
||
194 | } |
||
195 | |||
196 | return $this->makeObject(-1, $err_msg); |
||
197 | } |
||
198 | if(!$result->post) |
||
199 | { |
||
200 | return $this->makeObject(-1, 'msg_krzip_riddling_wrong'); |
||
201 | } |
||
202 | |||
203 | $item_list = $result->post->itemlist->item; |
||
204 | if(!is_array($item_list)) |
||
205 | { |
||
206 | $item_list = array($item_list); |
||
207 | } |
||
208 | if(!$item_list) |
||
|
|||
209 | { |
||
210 | return $this->makeObject(-1, 'msg_krzip_no_result'); |
||
211 | } |
||
212 | |||
213 | $addr_list = array(); |
||
214 | foreach($item_list as $key => $val) |
||
215 | { |
||
216 | $postcode = $val->postcd->body; |
||
217 | $road_addr = $val->address->body; |
||
218 | $jibun_addr = $val->addrjibun->body; |
||
219 | $detail = ''; |
||
220 | $extra = ''; |
||
221 | |||
222 | View Code Duplication | if(preg_match('/\((?<detail>.+[읍면동리(마을)(0-9+가)](?:,.*)?)\)/', $road_addr, $matches)) |
|
223 | { |
||
224 | $road_addr = trim(str_replace($matches[0], '', $road_addr)); |
||
225 | $extra = '(' . $matches['detail'] . ')'; |
||
226 | } |
||
227 | View Code Duplication | if(preg_match('/\((?<detail>.+[읍면동리(마을)(빌딩)(0-9+가)](?:,.*)?)\)/', $jibun_addr, $matches)) |
|
228 | { |
||
229 | $jibun_addr = '(' . trim(str_replace($matches[0], '', $jibun_addr)) . ')'; |
||
230 | } |
||
231 | |||
232 | $addr_list[] = array( |
||
233 | $postcode, // 0 우편번호 |
||
234 | $road_addr, // 1 도로명 주소 |
||
235 | $jibun_addr, // 2 지번 주소 |
||
236 | $detail, // 3 상세 주소 |
||
237 | $extra // 4 부가 정보 (**동, **빌딩) |
||
238 | ); |
||
239 | } |
||
240 | |||
241 | $output = $this->makeObject(); |
||
242 | $output->add('address_list', $addr_list); |
||
243 | |||
244 | return $output; |
||
245 | } |
||
246 | |||
272 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.