| Conditions | 8 |
| Paths | 48 |
| Total Lines | 156 |
| Code Lines | 84 |
| 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 |
||
| 40 | public function initialize($entity = null): void |
||
| 41 | { |
||
| 42 | // Не нужны провайдеру |
||
| 43 | // Busylevel |
||
| 44 | // Extension |
||
| 45 | // Networkfilterid |
||
| 46 | |||
| 47 | // ProviderType |
||
| 48 | $this->add(new Hidden('providerType', ['value' => 'SIP'])); |
||
| 49 | |||
| 50 | // Disabled |
||
| 51 | $this->add(new Hidden('disabled')); |
||
| 52 | |||
| 53 | // ID |
||
| 54 | $this->add(new Hidden('id')); |
||
| 55 | |||
| 56 | // Uniqid |
||
| 57 | $this->add(new Hidden('uniqid')); |
||
| 58 | |||
| 59 | // Type |
||
| 60 | $this->add(new Hidden('type')); |
||
| 61 | |||
| 62 | |||
| 63 | // Description |
||
| 64 | $this->add(new Text('description')); |
||
| 65 | |||
| 66 | // Username |
||
| 67 | $this->add(new Text('username')); |
||
| 68 | |||
| 69 | // Secret |
||
| 70 | $this->add(new Password('secret')); |
||
| 71 | |||
| 72 | // Host |
||
| 73 | $this->add(new Text('host')); |
||
| 74 | |||
| 75 | // Dtmfmode |
||
| 76 | $arrDTMFType = [ |
||
| 77 | 'auto' => $this->translation->_('auto'), |
||
| 78 | 'inband' => $this->translation->_('inband'), |
||
| 79 | 'info' => $this->translation->_('info'), |
||
| 80 | 'rfc4733' => $this->translation->_('rfc4733'), |
||
| 81 | 'auto_info' => $this->translation->_('auto_info'), |
||
| 82 | ]; |
||
| 83 | |||
| 84 | $dtmfmode = new Select( |
||
| 85 | 'dtmfmode', $arrDTMFType, [ |
||
| 86 | 'using' => [ |
||
| 87 | 'id', |
||
| 88 | 'name', |
||
| 89 | ], |
||
| 90 | 'useEmpty' => false, |
||
| 91 | 'value' => $entity->dtmfmode, |
||
| 92 | 'class' => 'ui selection dropdown', |
||
| 93 | ] |
||
| 94 | ); |
||
| 95 | $this->add($dtmfmode); |
||
| 96 | |||
| 97 | $regTypeArray = [ |
||
| 98 | Sip::REG_TYPE_OUTBOUND => $this->translation->_('sip_REG_TYPE_OUTBOUND'), |
||
| 99 | Sip::REG_TYPE_INBOUND => $this->translation->_('sip_REG_TYPE_INBOUND'), |
||
| 100 | Sip::REG_TYPE_NONE => $this->translation->_('sip_REG_TYPE_NONE'), |
||
| 101 | ]; |
||
| 102 | |||
| 103 | $regTypeValue = $entity->registration_type; |
||
| 104 | if(empty($regTypeValue)){ |
||
| 105 | $regTypeValue = ($entity->noregister === '0')?Sip::REG_TYPE_OUTBOUND: Sip::REG_TYPE_NONE; |
||
| 106 | } |
||
| 107 | $regType = new Select( |
||
| 108 | 'registration_type', $regTypeArray, [ |
||
| 109 | 'using' => [ |
||
| 110 | 'id', |
||
| 111 | 'name', |
||
| 112 | ], |
||
| 113 | 'useEmpty' => false, |
||
| 114 | 'value' => $regTypeValue, |
||
| 115 | 'class' => 'ui selection dropdown', |
||
| 116 | ] |
||
| 117 | ); |
||
| 118 | $this->add($regType); |
||
| 119 | |||
| 120 | // Transport |
||
| 121 | $arrTransport = [ |
||
| 122 | Sip::TRANSPORT_UDP => Sip::TRANSPORT_UDP, |
||
| 123 | Sip::TRANSPORT_TCP => Sip::TRANSPORT_TCP, |
||
| 124 | Sip::TRANSPORT_TLS => Sip::TRANSPORT_TLS, |
||
| 125 | ]; |
||
| 126 | $transport = new Select( |
||
| 127 | 'transport', $arrTransport, [ |
||
| 128 | 'using' => [ |
||
| 129 | 'id', |
||
| 130 | 'name', |
||
| 131 | ], |
||
| 132 | 'emptyText' => 'udp, tcp', |
||
| 133 | 'emptyValue' => ' ', |
||
| 134 | 'useEmpty' => true, |
||
| 135 | 'value' => empty($entity->transport)?' ': $entity->transport, |
||
| 136 | 'class' => 'ui selection dropdown', |
||
| 137 | ] |
||
| 138 | ); |
||
| 139 | $this->add($transport); |
||
| 140 | |||
| 141 | // Port |
||
| 142 | $this->add(new Numeric('port')); |
||
| 143 | $this->add(new Text('outbound_proxy')); |
||
| 144 | |||
| 145 | // Nat |
||
| 146 | $arrNatType = [ |
||
|
|
|||
| 147 | 'force_rport,comedia' => 'force_rport, comedia', |
||
| 148 | 'force_rport' => 'force_rport', |
||
| 149 | 'comedia' => 'comedia', |
||
| 150 | 'auto_force_rport' => 'auto_force_rport', |
||
| 151 | 'no' => 'no', |
||
| 152 | ]; |
||
| 153 | |||
| 154 | // Qualify |
||
| 155 | $cheskarr = ['value' => null]; |
||
| 156 | if ($entity->qualify) { |
||
| 157 | $cheskarr = ['checked' => 'checked', 'value' => null]; |
||
| 158 | } |
||
| 159 | |||
| 160 | $this->add(new Check('qualify', $cheskarr)); |
||
| 161 | |||
| 162 | // Qualifyfreq |
||
| 163 | $this->add(new Numeric('qualifyfreq')); |
||
| 164 | |||
| 165 | // Fromuser |
||
| 166 | $this->add(new Text('fromuser')); |
||
| 167 | |||
| 168 | // Fromdomain |
||
| 169 | $this->add(new Text('fromdomain')); |
||
| 170 | |||
| 171 | // Noregister |
||
| 172 | $cheskarr = ['value' => null]; |
||
| 173 | if ($entity->noregister) { |
||
| 174 | $cheskarr = ['checked' => 'checked', 'value' => null]; |
||
| 175 | } |
||
| 176 | $this->add(new Check('noregister', $cheskarr)); |
||
| 177 | |||
| 178 | |||
| 179 | // Disablefromuser |
||
| 180 | $cheskarr = ['value' => null]; |
||
| 181 | if ($entity->disablefromuser) { |
||
| 182 | $cheskarr = ['checked' => 'checked', 'value' => null]; |
||
| 183 | } |
||
| 184 | $this->add(new Check('disablefromuser', $cheskarr)); |
||
| 185 | |||
| 186 | // Receive_calls_without_auth |
||
| 187 | $cheskarr = ['value' => null]; |
||
| 188 | if ($entity->receive_calls_without_auth) { |
||
| 189 | $cheskarr = ['checked' => 'checked', 'value' => null]; |
||
| 190 | } |
||
| 191 | $this->add(new Check('receive_calls_without_auth', $cheskarr)); |
||
| 192 | |||
| 193 | // Manualattributes |
||
| 194 | $rows = max(round(strlen($entity->manualattributes) / 95), 2); |
||
| 195 | $this->add(new TextArea('manualattributes', ["rows" => $rows])); |
||
| 196 | } |
||
| 197 | } |