| Conditions | 15 |
| Paths | 69 |
| Total Lines | 56 |
| 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 |
||
| 167 | private static function hangupChanCheckSipTrtansfer(WorkerCallEvents $worker, $data, $channels):void{ |
||
| 168 | $not_local = (stripos($data['agi_channel'], 'local/') === false); |
||
| 169 | if($not_local === false || $data['OLD_LINKEDID'] !== $data['linkedid']) { |
||
| 170 | return; |
||
| 171 | } |
||
| 172 | $am = Util::getAstManager('off'); |
||
| 173 | $active_chans = $am->GetChannels(false); |
||
| 174 | // Намек на SIP трансфер. |
||
| 175 | foreach ($channels as $data_chan) { |
||
| 176 | if ( ! in_array($data_chan['chan'], $active_chans, true)) { |
||
| 177 | // Вызов уже завершен. Не интересно. |
||
| 178 | continue; |
||
| 179 | } |
||
| 180 | $BRIDGEPEER = $am->GetVar($data_chan['chan'], 'BRIDGEPEER', null, false); |
||
| 181 | if ( !is_string($BRIDGEPEER) || ! in_array($BRIDGEPEER, $active_chans, true)) { |
||
| 182 | // Вызов уже завершен. Не интересно. |
||
| 183 | continue; |
||
| 184 | } |
||
| 185 | |||
| 186 | $linkedid = $am->GetVar($data_chan['chan'], 'CHANNEL(linkedid)', null, false); |
||
| 187 | if ( empty($linkedid) || $linkedid === $data['linkedid']) { |
||
| 188 | continue; |
||
| 189 | } |
||
| 190 | |||
| 191 | $CALLERID = $am->GetVar($BRIDGEPEER, 'CALLERID(num)', null, false); |
||
| 192 | $n_data['action'] = 'sip_transfer'; |
||
| 193 | $n_data['src_chan'] = $data_chan['out'] ? $data_chan['chan'] : $BRIDGEPEER; |
||
| 194 | $n_data['src_num'] = $data_chan['out'] ? $data_chan['num'] : $CALLERID; |
||
| 195 | $n_data['dst_chan'] = $data_chan['out'] ? $BRIDGEPEER : $data_chan['chan']; |
||
| 196 | $n_data['dst_num'] = $data_chan['out'] ? $CALLERID : $data_chan['num']; |
||
| 197 | $n_data['start'] = date('Y-m-d H:i:s'); |
||
| 198 | $n_data['answer'] = date('Y-m-d H:i:s'); |
||
| 199 | $n_data['linkedid'] = $linkedid; |
||
| 200 | $n_data['UNIQUEID'] = $data['linkedid'] . Util::generateRandomString(); |
||
| 201 | $n_data['transfer'] = '0'; |
||
| 202 | if($worker->enableMonitor($n_data['src_num']??'', $n_data['dst_num']??'')){ |
||
| 203 | $n_data['recordingfile'] = $worker->MixMonitor($n_data['dst_chan'], $n_data['UNIQUEID'], null, null, 'hangupChanCheckSipTrtansfer'); |
||
| 204 | } |
||
| 205 | $n_data['did'] = $data_chan['did']; |
||
| 206 | |||
| 207 | InsertDataToDB::execute($n_data); |
||
| 208 | $filter = [ |
||
| 209 | 'linkedid=:linkedid:', |
||
| 210 | 'bind' => ['linkedid' => $data['linkedid']], |
||
| 211 | ]; |
||
| 212 | $m_data = CallDetailRecordsTmp::find($filter); |
||
| 213 | foreach ($m_data as $row) { |
||
| 214 | $row->writeAttribute('linkedid', $linkedid); |
||
| 215 | $row->save(); |
||
| 216 | } |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Отправка UserEvent |
||
| 220 | */ |
||
| 221 | $AgiData = base64_encode(json_encode($n_data)); |
||
| 222 | $am->UserEvent('CdrConnector', ['AgiData' => $AgiData]); |
||
| 223 | } // Обход текущих каналов. |
||
| 225 | } |