| Conditions | 9 |
| Paths | 8 |
| Total Lines | 61 |
| 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 |
||
| 42 | public static function execute(WorkerCallEvents $worker, $data): void |
||
| 43 | { |
||
| 44 | $channel = $data['Channel'] ?? ''; |
||
| 45 | $worker->addActiveChan($channel, $data['LinkedID']); |
||
| 46 | |||
| 47 | // If no channel data, or if the channel is local, or if the channel is already active, return immediately |
||
| 48 | if (empty($channel) || stripos($channel, 'local') === 0 || $worker->existsActiveChan($channel)) { |
||
| 49 | return; |
||
| 50 | } |
||
| 51 | usleep(100000); // delay to ensure the channel is properly added |
||
| 52 | |||
| 53 | // Retrieve the linked identifier for the channel |
||
| 54 | $linkedId = Util::getAstManager('off')->GetVar($channel, 'CHANNEL(linkedid)', '', false); |
||
| 55 | |||
| 56 | // If the linkedId matches the data LinkedID, return immediately |
||
| 57 | if ($linkedId === $data['LinkedID']) { |
||
| 58 | return; |
||
| 59 | } |
||
| 60 | |||
| 61 | // This is a return call after consultative transfer |
||
| 62 | $filter = [ |
||
| 63 | 'linkedid=:linkedid: AND a_transfer = "1"', |
||
| 64 | 'bind' => [ |
||
| 65 | 'linkedid' => $linkedId, |
||
| 66 | ], |
||
| 67 | ]; |
||
| 68 | /** @var CallDetailRecordsTmp $m_data */ |
||
| 69 | /** @var CallDetailRecordsTmp $row */ |
||
| 70 | $m_data = CallDetailRecordsTmp::find($filter); |
||
| 71 | foreach ($m_data as $row) { |
||
| 72 | $row->a_transfer = '0'; |
||
| 73 | $row->save(); |
||
| 74 | if ($worker->existsActiveChan($row->src_chan)) { |
||
| 75 | $chan = $row->src_chan; |
||
| 76 | $number = $row->src_num; |
||
| 77 | } elseif ($worker->existsActiveChan($row->dst_chan)) { |
||
| 78 | $chan = $row->dst_chan; |
||
| 79 | $number = $row->dst_num; |
||
| 80 | } else { |
||
| 81 | continue; |
||
| 82 | } |
||
| 83 | |||
| 84 | // Data for the returned call after transfer |
||
| 85 | $insert_data['action'] = "ret_after_trasfer"; |
||
| 86 | $insert_data['start'] = date('Y-m-d H:i:s.v', str_replace('mikopbx-', '', $data['LinkedID'])); |
||
| 87 | $insert_data['answer'] = $data['EventTime']; |
||
| 88 | $insert_data['src_chan'] = $chan; |
||
| 89 | $insert_data['src_num'] = $number; |
||
| 90 | $insert_data['dst_chan'] = $channel; |
||
| 91 | $insert_data['dst_num'] = $data['CallerIDnum']; |
||
| 92 | $insert_data['linkedid'] = $linkedId; |
||
| 93 | $insert_data['UNIQUEID'] = $data['UniqueID'] . "_" . Util::generateRandomString(); |
||
| 94 | $insert_data['did'] = $row->did; |
||
| 95 | $insert_data['transfer'] = '0'; |
||
| 96 | |||
| 97 | if ($worker->enableMonitor($insert_data['src_num'] ?? '', $insert_data['dst_num'] ?? '')) { |
||
| 98 | $insert_data['recordingfile'] = $worker->MixMonitor($insert_data['dst_chan'], $insert_data['UNIQUEID'], '', '', 'ret_after_trasfer'); |
||
| 99 | } |
||
| 100 | |||
| 101 | // Insert the new data into the database |
||
| 102 | InsertDataToDB::execute($insert_data); |
||
| 103 | } |
||
| 106 | } |