| Conditions | 14 |
| Paths | 96 |
| Total Lines | 58 |
| Code Lines | 35 |
| 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 |
||
| 34 | public static function execute(WorkerCallEvents $worker, $data):void |
||
| 35 | { |
||
| 36 | clearstatcache(); |
||
| 37 | $recordingfile = ''; |
||
| 38 | $dest_chan = "MeetMe:{$data['conference']}"; |
||
| 39 | // Отбираем все строки по текущей конференции. Не завершенные вызовы. |
||
| 40 | $filter = [ |
||
| 41 | 'dst_chan=:dst_chan: OR linkedid=:linkedid:', |
||
| 42 | 'bind' => [ |
||
| 43 | 'linkedid' => $data['linkedid'], |
||
| 44 | 'dst_chan' => $dest_chan, |
||
| 45 | ], |
||
| 46 | ]; |
||
| 47 | $m_data = CallDetailRecordsTmp::find($filter); |
||
| 48 | /** @var CallDetailRecordsTmp $row */ |
||
| 49 | foreach ($m_data as $row) { |
||
| 50 | if ($dest_chan === $row->dst_chan) { |
||
| 51 | $is_local = (stripos($data['src_chan'], 'local/') !== false); |
||
| 52 | $is_stored_local = (stripos($row->src_chan, 'local/') !== false); |
||
| 53 | if ($row->UNIQUEID === $data['UNIQUEID'] && $is_local && ! $is_stored_local) { |
||
| 54 | $data['src_chan'] = $row->src_chan; |
||
| 55 | } |
||
| 56 | if (file_exists($row->recordingfile) || file_exists( |
||
| 57 | Util::trimExtensionForFile($row->recordingfile) . '.wav' |
||
| 58 | )) { |
||
| 59 | // Переопределим путь к файлу записи разговора. Для конферецнии файл один. |
||
| 60 | $recordingfile = $row->recordingfile; |
||
| 61 | } |
||
| 62 | } |
||
| 63 | if ($row->linkedid === $data['meetme_id']) { |
||
| 64 | continue; |
||
| 65 | } |
||
| 66 | // Подменим ID на идентификатор конференции. |
||
| 67 | $row->writeAttribute('linkedid', $data['meetme_id']); |
||
| 68 | $res = $row->save(); |
||
| 69 | if ( ! $res) { |
||
| 70 | Util::sysLogMsg('Action_hangup_chan_meetme', implode(' ', $row->getMessages()), LOG_DEBUG); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | /** @var CallDetailRecordsTmp $m_data */ |
||
| 75 | /** @var CallDetailRecordsTmp $row */ |
||
| 76 | /** @var CallDetailRecordsTmp $rec_data */ |
||
| 77 | foreach ($m_data as $row) { |
||
| 78 | if ($row->src_chan !== $data['src_chan']) { |
||
| 79 | continue; |
||
| 80 | } |
||
| 81 | // Заполняем данные для текущего оповещения. |
||
| 82 | $row->writeAttribute('endtime', $data['end']); |
||
| 83 | $row->writeAttribute('transfer', 0); |
||
| 84 | $row->writeAttribute('linkedid', $data['meetme_id']); |
||
| 85 | |||
| 86 | if ( ! empty($recordingfile)) { |
||
| 87 | $row->writeAttribute('recordingfile', $recordingfile); |
||
| 88 | } |
||
| 89 | $res = $row->save(); |
||
| 90 | if ( ! $res) { |
||
| 91 | Util::sysLogMsg('Action_hangup_chan_meetme', implode(' ', $row->getMessages()), LOG_DEBUG); |
||
| 92 | } |
||
| 96 | } |