| Conditions | 16 |
| Paths | 274 |
| Total Lines | 70 |
| Code Lines | 52 |
| 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 |
||
| 43 | public static function execute(WorkerCallEvents $worker, array $data): void |
||
| 44 | { |
||
| 45 | $extra = json_decode($data['Extra'], true); |
||
| 46 | $am = Util::getAstManager('off'); |
||
| 47 | if(stripos($extra['transferee_channel_name'],'local') === 0){ |
||
| 48 | $chanTarget = $am->GetVar($extra['transferee_channel_name'],'ATTENDEDTRANSFER', '' ,false); |
||
| 49 | }else{ |
||
| 50 | $chanTarget = $extra['transferee_channel_name']; |
||
| 51 | } |
||
| 52 | $chanId1 = $worker->getActiveChanId($extra['channel2_name']); |
||
| 53 | $chanId2 = $worker->getActiveChanId($chanTarget); |
||
| 54 | if(empty($chanId1) || empty($chanId2)){ |
||
| 55 | return; |
||
| 56 | } |
||
| 57 | |||
| 58 | if($chanId1 !== $chanId2){ |
||
| 59 | $filter = [ |
||
| 60 | 'linkedid=:linkedid1: OR linkedid=:linkedid2:', |
||
| 61 | 'bind' => [ |
||
| 62 | 'linkedid1' => $chanId1, |
||
| 63 | 'linkedid2' => $chanId2, |
||
| 64 | ], |
||
| 65 | ]; |
||
| 66 | $n_data=[]; |
||
| 67 | $n_data['action'] = 'sip_transfer'; |
||
| 68 | /** @var CallDetailRecordsTmp $row */ |
||
| 69 | $m_data = CallDetailRecordsTmp::find($filter); |
||
| 70 | foreach ($m_data as $row){ |
||
| 71 | if(empty($row->endtime)){ |
||
| 72 | if(in_array($row->src_chan, [$extra['channel2_name'], $data['Channel']], true)) { |
||
| 73 | $n_data['dst_chan'] = $row->dst_chan; |
||
| 74 | $n_data['dst_num'] = $row->dst_num; |
||
| 75 | $n_data['did'] = $row->did; |
||
| 76 | $worker->StopMixMonitor($n_data['dst_chan']); |
||
| 77 | }elseif(in_array($row->dst_chan, [$extra['channel2_name'], $data['Channel']], true)){ |
||
| 78 | $n_data['src_chan'] = $row->src_chan; |
||
| 79 | $n_data['src_num'] = $row->src_num; |
||
| 80 | $n_data['did'] = $row->did; |
||
| 81 | $worker->StopMixMonitor($n_data['src_chan']); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | } |
||
| 85 | $m_data = CallDetailRecordsTmp::find($filter); |
||
| 86 | foreach ($m_data as $row) { |
||
| 87 | // Set new linked ID. |
||
| 88 | if($row->linkedid !== $chanId2){ |
||
| 89 | $row->writeAttribute('linkedid', $chanId2); |
||
| 90 | } |
||
| 91 | if(empty($row->endtime)){ |
||
| 92 | if(in_array($row->src_chan, [$extra['channel2_name'], $data['Channel']], true)) { |
||
| 93 | $row->writeAttribute('endtime', date('Y-m-d H:i:s')); |
||
| 94 | }elseif(in_array($row->dst_chan, [$extra['channel2_name'], $data['Channel']], true)){ |
||
| 95 | $row->writeAttribute('endtime', date('Y-m-d H:i:s')); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | $row->save(); |
||
| 99 | } |
||
| 100 | $n_data['start'] = date('Y-m-d H:i:s'); |
||
| 101 | $n_data['answer'] = date('Y-m-d H:i:s'); |
||
| 102 | $n_data['linkedid'] = $chanId2; |
||
| 103 | $n_data['UNIQUEID'] = $chanId2 . Util::generateRandomString(); |
||
| 104 | $n_data['transfer'] = '0'; |
||
| 105 | if(isset($n_data['dst_chan'], $n_data['src_chan'])){ |
||
| 106 | if ($worker->enableMonitor($n_data['src_num'] ?? '', $n_data['dst_num'] ?? '')) { |
||
| 107 | $n_data['recordingfile'] = $worker->MixMonitor($n_data['dst_chan'], $n_data['UNIQUEID'], '', '', 'hangupChanCheckSipAttTrtansfer'); |
||
| 108 | } |
||
| 109 | InsertDataToDB::execute($n_data); |
||
| 110 | // Sending UserEvent |
||
| 111 | $AgiData = base64_encode(json_encode($n_data)); |
||
| 112 | $am->UserEvent('CdrConnector', ['AgiData' => $AgiData]); |
||
| 113 | } |
||
| 116 | } |