Conditions | 14 |
Paths | 37 |
Total Lines | 54 |
Code Lines | 37 |
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 |
||
148 | private static function hangupChanCheckSipTrtansfer($worker, $data, $channels):void{ |
||
149 | $not_local = (stripos($data['agi_channel'], 'local/') === false); |
||
150 | if($not_local === false || $data['OLD_LINKEDID'] !== $data['linkedid']) { |
||
151 | return; |
||
152 | } |
||
153 | $am = Util::getAstManager('off'); |
||
154 | $active_chans = $am->GetChannels(false); |
||
155 | // Намек на SIP трансфер. |
||
156 | foreach ($channels as $data_chan) { |
||
157 | if ( ! in_array($data_chan['chan'], $active_chans, true)) { |
||
158 | // Вызов уже завершен. Не интересно. |
||
159 | continue; |
||
160 | } |
||
161 | $BRIDGEPEER = $am->GetVar($data_chan['chan'], 'BRIDGEPEER', null, false); |
||
162 | if ( !is_string($BRIDGEPEER) || ! in_array($BRIDGEPEER, $active_chans, true)) { |
||
163 | // Вызов уже завершен. Не интересно. |
||
164 | continue; |
||
165 | } |
||
166 | |||
167 | $linkedid = $am->GetVar($data_chan['chan'], 'CHANNEL(linkedid)', null, false); |
||
168 | if ( empty($linkedid) || $linkedid === $data['linkedid']) { |
||
169 | continue; |
||
170 | } |
||
171 | |||
172 | $CALLERID = $am->GetVar($BRIDGEPEER, 'CALLERID(num)', null, false); |
||
173 | $n_data['action'] = 'sip_transfer'; |
||
174 | $n_data['src_chan'] = $data_chan['out'] ? $data_chan['chan'] : $BRIDGEPEER; |
||
175 | $n_data['src_num'] = $data_chan['out'] ? $data_chan['num'] : $CALLERID; |
||
176 | $n_data['dst_chan'] = $data_chan['out'] ? $BRIDGEPEER : $data_chan['chan']; |
||
177 | $n_data['dst_num'] = $data_chan['out'] ? $CALLERID : $data_chan['num']; |
||
178 | $n_data['start'] = date('Y-m-d H:i:s'); |
||
179 | $n_data['answer'] = date('Y-m-d H:i:s'); |
||
180 | $n_data['linkedid'] = $linkedid; |
||
181 | $n_data['UNIQUEID'] = $data['linkedid'] . Util::generateRandomString(); |
||
182 | $n_data['transfer'] = '0'; |
||
183 | $n_data['recordingfile'] = $worker->MixMonitor($n_data['dst_chan'], $n_data['UNIQUEID']); |
||
184 | $n_data['did'] = $data_chan['did']; |
||
185 | |||
186 | InsertDataToDB::execute($n_data); |
||
187 | $filter = [ |
||
188 | 'linkedid=:linkedid:', |
||
189 | 'bind' => ['linkedid' => $data['linkedid']], |
||
190 | ]; |
||
191 | $m_data = CallDetailRecordsTmp::find($filter); |
||
192 | foreach ($m_data as $row) { |
||
193 | $row->writeAttribute('linkedid', $linkedid); |
||
194 | $row->save(); |
||
195 | } |
||
196 | |||
197 | /** |
||
198 | * Отправка UserEvent |
||
199 | */ |
||
200 | $AgiData = base64_encode(json_encode($n_data)); |
||
201 | $am->UserEvent('CdrConnector', ['AgiData' => $AgiData]); |
||
202 | } // Обход текущих каналов. |
||
204 | } |