| Conditions | 11 |
| Paths | 92 |
| Total Lines | 52 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 31 | public static function execute($filter):string |
||
| 32 | { |
||
| 33 | |||
| 34 | if(self::filterNotValid($filter)){ |
||
| 35 | return '[]'; |
||
| 36 | } |
||
| 37 | |||
| 38 | $res = null; |
||
| 39 | try { |
||
| 40 | if (isset($filter['miko_tmp_db'])) { |
||
| 41 | $res = CallDetailRecordsTmp::find($filter); |
||
| 42 | } else { |
||
| 43 | $res = CallDetailRecords::find($filter); |
||
| 44 | } |
||
| 45 | $res_data = json_encode($res->toArray()); |
||
| 46 | } catch (Throwable $e) { |
||
| 47 | $res_data = '[]'; |
||
| 48 | } |
||
| 49 | |||
| 50 | if ($res && isset($filter['add_pack_query'])) { |
||
| 51 | $arr = []; |
||
| 52 | foreach ($res->toArray() as $row) { |
||
| 53 | $arr[] = $row[$filter['columns']]; |
||
| 54 | } |
||
| 55 | $filter['add_pack_query']['bind'][$filter['columns']] = $arr; |
||
| 56 | |||
| 57 | if(self::filterNotValid($filter['add_pack_query'])){ |
||
| 58 | return '[]'; |
||
| 59 | } |
||
| 60 | |||
| 61 | try { |
||
| 62 | $res = CallDetailRecords::find($filter['add_pack_query']); |
||
| 63 | $res_data = json_encode($res->toArray(), JSON_THROW_ON_ERROR); |
||
| 64 | } catch (Throwable $e) { |
||
| 65 | $res_data = '[]'; |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | if (isset($filter['miko_result_in_file'])) { |
||
| 70 | $di = Di::getDefault(); |
||
| 71 | if($di){ |
||
| 72 | $dirsConfig = $di->getShared('config'); |
||
| 73 | $filename = $dirsConfig->path('core.tempDir') . '/' . md5(microtime(true)); |
||
| 74 | }else{ |
||
| 75 | $filename = '/tmp/' . md5(microtime(true)); |
||
| 76 | } |
||
| 77 | file_put_contents($filename, $res_data); |
||
| 78 | Util::addRegularWWWRights($filename); |
||
| 79 | $res_data = json_encode($filename); |
||
| 80 | } |
||
| 81 | |||
| 82 | return $res_data; |
||
| 83 | |||
| 109 | } |