| Conditions | 11 |
| Paths | 92 |
| Total Lines | 56 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 32 | public static function execute($filter):string |
||
| 33 | { |
||
| 34 | |||
| 35 | if(self::filterNotValid($filter)){ |
||
| 36 | return '[]'; |
||
| 37 | } |
||
| 38 | |||
| 39 | $res = null; |
||
| 40 | try { |
||
| 41 | if (isset($filter['miko_tmp_db'])) { |
||
| 42 | $res = CallDetailRecordsTmp::find($filter); |
||
| 43 | } else { |
||
| 44 | $res = CallDetailRecords::find($filter); |
||
| 45 | } |
||
| 46 | $res_data = json_encode($res->toArray()); |
||
| 47 | } catch (Throwable $e) { |
||
| 48 | $res_data = '[]'; |
||
| 49 | } |
||
| 50 | |||
| 51 | if ($res && isset($filter['add_pack_query'])) { |
||
| 52 | $arr = []; |
||
| 53 | foreach ($res->toArray() as $row) { |
||
| 54 | $arr[] = $row[$filter['columns']]; |
||
| 55 | } |
||
| 56 | $filter['add_pack_query']['bind'][$filter['columns']] = $arr; |
||
| 57 | |||
| 58 | if(self::filterNotValid($filter['add_pack_query'])){ |
||
| 59 | return '[]'; |
||
| 60 | } |
||
| 61 | |||
| 62 | try { |
||
| 63 | $res = CallDetailRecords::find($filter['add_pack_query']); |
||
| 64 | $res_data = json_encode($res->toArray(), JSON_THROW_ON_ERROR); |
||
| 65 | } catch (Throwable $e) { |
||
| 66 | $res_data = '[]'; |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | if (isset($filter['miko_result_in_file'])) { |
||
| 71 | [$tmpDir, $downloadCacheDir] = self::getTmpDir(); |
||
| 72 | $fileBaseName = md5(microtime(true)); |
||
| 73 | // temp- в названии файла необходямо, чтобы файл был автоматом удален через 5 минут. |
||
| 74 | $filename = $tmpDir.'/temp-'.$fileBaseName; |
||
| 75 | file_put_contents($filename, $res_data); |
||
| 76 | |||
| 77 | if(!empty($downloadCacheDir)){ |
||
| 78 | $linkName = $downloadCacheDir.'/'.$fileBaseName; |
||
| 79 | // Для автоматического удаления файла. |
||
| 80 | // Файл с такой ссылкой будет удален через 5 минут по cron. |
||
| 81 | Util::createUpdateSymlink($filename, $linkName,true); |
||
| 82 | } |
||
| 83 | Util::addRegularWWWRights($filename); |
||
| 84 | $res_data = json_encode($filename); |
||
| 85 | } |
||
| 86 | |||
| 87 | return $res_data; |
||
| 88 | |||
| 137 | } |