| Conditions | 14 |
| Paths | 37 |
| Total Lines | 55 |
| Code Lines | 38 |
| 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 |
||
| 100 | private static function hangupChanCheckSipTrtansfer($worker, $data, $channels):void{ |
||
| 101 | $not_local = (stripos($data['agi_channel'], 'local/') === false); |
||
| 102 | if($not_local === false || $data['OLD_LINKEDID'] !== $data['linkedid']) { |
||
| 103 | return; |
||
| 104 | } |
||
| 105 | $am = Util::getAstManager('off'); |
||
| 106 | $active_chans = $am->GetChannels(false); |
||
| 107 | // Намек на SIP трансфер. |
||
| 108 | foreach ($channels as $data_chan) { |
||
| 109 | if ( ! in_array($data_chan['chan'], $active_chans, true)) { |
||
| 110 | // Вызов уже завершен. Не интересно. |
||
| 111 | continue; |
||
| 112 | } |
||
| 113 | $BRIDGEPEER = $am->GetVar($data_chan['chan'], 'BRIDGEPEER', null, false); |
||
| 114 | if ( !is_string($BRIDGEPEER) || ! in_array($BRIDGEPEER, $active_chans, true)) { |
||
| 115 | // Вызов уже завершен. Не интересно. |
||
| 116 | continue; |
||
| 117 | } |
||
| 118 | |||
| 119 | $linkedid = $am->GetVar($data_chan['chan'], 'CHANNEL(linkedid)', null, false); |
||
| 120 | if ( empty($linkedid) || $linkedid === $data['linkedid']) { |
||
| 121 | continue; |
||
| 122 | } |
||
| 123 | |||
| 124 | $CALLERID = $am->GetVar($BRIDGEPEER, 'CALLERID(num)', null, false); |
||
| 125 | $n_data['action'] = 'sip_transfer'; |
||
| 126 | $n_data['src_chan'] = $data_chan['out'] ? $data_chan['chan'] : $BRIDGEPEER; |
||
| 127 | $n_data['src_num'] = $data_chan['out'] ? $data_chan['num'] : $CALLERID; |
||
| 128 | $n_data['dst_chan'] = $data_chan['out'] ? $BRIDGEPEER : $data_chan['chan']; |
||
| 129 | $n_data['dst_num'] = $data_chan['out'] ? $CALLERID : $data_chan['num']; |
||
| 130 | $n_data['start'] = date('Y-m-d H:i:s'); |
||
| 131 | $n_data['answer'] = date('Y-m-d H:i:s'); |
||
| 132 | $n_data['linkedid'] = $linkedid; |
||
| 133 | $n_data['UNIQUEID'] = $data['linkedid'] . Util::generateRandomString(); |
||
| 134 | $n_data['transfer'] = '0'; |
||
| 135 | $n_data['recordingfile'] = $worker->MixMonitor($n_data['dst_chan'], $n_data['UNIQUEID']); |
||
| 136 | $n_data['did'] = $data_chan['did']; |
||
| 137 | |||
| 138 | Util::logMsgDb('call_events', json_encode($n_data)); |
||
| 139 | InsertDataToDB::execute($n_data); |
||
| 140 | $filter = [ |
||
| 141 | 'linkedid=:linkedid:', |
||
| 142 | 'bind' => ['linkedid' => $data['linkedid']], |
||
| 143 | ]; |
||
| 144 | $m_data = CallDetailRecordsTmp::find($filter); |
||
| 145 | foreach ($m_data as $row) { |
||
| 146 | $row->writeAttribute('linkedid', $linkedid); |
||
| 147 | $row->save(); |
||
| 148 | } |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Отправка UserEvent |
||
| 152 | */ |
||
| 153 | $AgiData = base64_encode(json_encode($n_data)); |
||
| 154 | $am->UserEvent('CdrConnector', ['AgiData' => $AgiData]); |
||
| 155 | } // Обход текущих каналов. |
||
| 157 | } |