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