| Conditions | 21 |
| Paths | 375 |
| Total Lines | 81 |
| Code Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 | private static function hangupChanEndCalls($worker, array $data, array &$transfer_calls, array &$channels):void{ |
||
| 43 | $filter = [ |
||
| 44 | 'linkedid=:linkedid: AND endtime = ""', |
||
| 45 | 'bind' => [ |
||
| 46 | 'linkedid' => $data['linkedid'], |
||
| 47 | ], |
||
| 48 | ]; |
||
| 49 | /** @var CallDetailRecordsTmp $m_data */ |
||
| 50 | /** @var CallDetailRecordsTmp $row */ |
||
| 51 | $m_data = CallDetailRecordsTmp::find($filter); |
||
| 52 | $countRows = 0; |
||
| 53 | $transferCdrAnswered = true; |
||
| 54 | foreach ($m_data as $row) { |
||
| 55 | if($row->dst_chan !== $data['agi_channel'] && $data['agi_channel'] !== $row->src_chan){ |
||
| 56 | continue; |
||
| 57 | } |
||
| 58 | $countRows++; |
||
| 59 | $vmState = $data['VMSTATUS']??''; |
||
| 60 | if($row->dst_num === VoiceMailConf::VOICE_MAIL_EXT && $vmState !== 'FAILED'){ |
||
| 61 | // Этот вызов будет заверщен событием voicemail_end |
||
| 62 | continue; |
||
| 63 | } |
||
| 64 | if ($row->transfer === '1' && !empty($row->dst_chan)) { |
||
| 65 | // Обязательно канал назначения не должен быть пустым. |
||
| 66 | // Иначе это не переадресация. |
||
| 67 | $transfer_calls[] = $row->toArray(); |
||
| 68 | $transferCdrAnswered = min($transferCdrAnswered, empty($row->answer)); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | foreach ($m_data as $row) { |
||
| 72 | if($row->dst_chan !== $data['agi_channel'] && $data['agi_channel'] !== $row->src_chan){ |
||
| 73 | continue; |
||
| 74 | } |
||
| 75 | $vmState = $data['VMSTATUS']??''; |
||
| 76 | if($row->dst_num === VoiceMailConf::VOICE_MAIL_EXT && $vmState !== 'FAILED'){ |
||
| 77 | // Этот вызов будет заверщен событием voicemail_end |
||
| 78 | continue; |
||
| 79 | } |
||
| 80 | if ($row->dialstatus === 'ORIGINATE') { |
||
| 81 | $row->writeAttribute('dialstatus', ''); |
||
| 82 | if($row->answer === ''){ |
||
| 83 | $newId = $row->linkedid.'_'.$row->src_num.'_'.substr($row->src_chan, strpos($row->src_chan,'-') +1); |
||
| 84 | $row->writeAttribute('UNIQUEID', $newId); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | $row->writeAttribute('endtime', $data['end']); |
||
| 88 | $row->writeAttribute('transfer', 0); |
||
| 89 | if($transferCdrAnswered === false && count($transfer_calls) === 2){ |
||
| 90 | // Завершение вызова при консультативной переадресации. Инициатор положил трубку до ответа dst. |
||
| 91 | $row->writeAttribute('a_transfer', 1); |
||
| 92 | } |
||
| 93 | if ($data['dialstatus'] !== '') { |
||
| 94 | if ($data['dialstatus'] === 'ORIGINATE') { |
||
| 95 | $row->writeAttribute('dst_chan', ''); |
||
| 96 | } |
||
| 97 | $row->writeAttribute('dialstatus', $data['dialstatus']); |
||
| 98 | } |
||
| 99 | $res = $row->update(); |
||
| 100 | if ( ! $res) { |
||
| 101 | Util::sysLogMsg('Action_hangup_chan', implode(' ', $row->getMessages()), LOG_DEBUG); |
||
| 102 | } |
||
| 103 | |||
| 104 | if ($row->src_chan !== $data['agi_channel']) { |
||
| 105 | $channels[] = [ |
||
| 106 | 'chan' => $row->src_chan, |
||
| 107 | 'did' => $row->did, |
||
| 108 | 'num' => $row->src_num, |
||
| 109 | 'out' => true, |
||
| 110 | ]; |
||
| 111 | } else { |
||
| 112 | $worker->StopMixMonitor($row->dst_chan, 'hangupChanEndCalls'); |
||
| 113 | $channels[] = [ |
||
| 114 | 'chan' => $row->dst_chan, |
||
| 115 | 'did' => $row->did, |
||
| 116 | 'num' => $row->dst_num, |
||
| 117 | 'out' => false, |
||
| 118 | ]; |
||
| 119 | } |
||
| 120 | } |
||
| 121 | |||
| 122 | self::regMissedCall($data, $countRows); |
||
| 123 | } |
||
| 225 | } |