| Conditions | 15 |
| Paths | 68 |
| Total Lines | 54 |
| Code Lines | 33 |
| 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 |
||
| 12 | public static function execute(WorkerCallEvents $worker, $data):void |
||
| 13 | { |
||
| 14 | $filter = self::getFilter($data); |
||
| 15 | $row_create = false; |
||
| 16 | /** @var CallDetailRecordsTmp $m_data */ |
||
| 17 | /** @var CallDetailRecordsTmp $row */ |
||
| 18 | $m_data = CallDetailRecordsTmp::find($filter); |
||
| 19 | foreach ($m_data as $row) { |
||
| 20 | if ( ! is_object($row)) { |
||
| 21 | continue; |
||
| 22 | } |
||
| 23 | /// |
||
| 24 | // Проверим, если более одного канала SIP/256 при входящем. |
||
| 25 | $column_chan_name = ('ORIGINATE' === $row->dialstatus) ? 'src_chan' : 'dst_chan'; |
||
| 26 | |||
| 27 | if ( ! empty($row->$column_chan_name) && $data['dst_chan'] !== $row->$column_chan_name) { |
||
| 28 | if ($row_create) { |
||
| 29 | continue; |
||
| 30 | } |
||
| 31 | // Необходимо дублировать строку звонка. |
||
| 32 | $new_row = new CallDetailRecordsTmp(); |
||
| 33 | $f_list = $row->toArray(); |
||
| 34 | foreach ($f_list as $attribute => $value) { |
||
| 35 | if ($attribute === 'id') { |
||
| 36 | continue; |
||
| 37 | } |
||
| 38 | $new_row->writeAttribute($attribute, $value); |
||
| 39 | } |
||
| 40 | $new_row->writeAttribute($column_chan_name, $data['dst_chan']); |
||
| 41 | $new_row->writeAttribute('UNIQUEID', $data['UNIQUEID'] . '_' . $data['dst_chan']); |
||
| 42 | // Подмена $row; |
||
| 43 | $row = $new_row; |
||
| 44 | $row_create = true; |
||
| 45 | } |
||
| 46 | // конец проверки |
||
| 47 | /// |
||
| 48 | if ($row->dialstatus === 'ORIGINATE') { |
||
| 49 | $account_col = 'from_account'; |
||
| 50 | // При оригинации меняется местами srs_chan в поле dst_chan. |
||
| 51 | $row->writeAttribute('src_chan', $data['dst_chan']); |
||
| 52 | } else { |
||
| 53 | $account_col = 'to_account'; |
||
| 54 | $row->writeAttribute('dst_chan', $data['dst_chan']); |
||
| 55 | } |
||
| 56 | |||
| 57 | if (isset($data['to_account']) && ! empty($data['to_account'])) { |
||
| 58 | $row->writeAttribute($account_col, $data['to_account']); |
||
| 59 | } |
||
| 60 | if (isset($data['dst_call_id']) && ! empty($data['dst_call_id'])) { |
||
| 61 | $row->writeAttribute('dst_call_id', $data['dst_call_id']); |
||
| 62 | } |
||
| 63 | $res = $row->save(); |
||
| 64 | if ( ! $res) { |
||
| 65 | Util::sysLogMsg('Action_dial_create_chan', implode(' ', $row->getMessages()), LOG_DEBUG); |
||
| 66 | } |
||
| 97 | } |