| Conditions | 30 |
| Paths | 2205 |
| Total Lines | 95 |
| Code Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 63 | public function saveAction(): void |
||
| 64 | { |
||
| 65 | if ( ! $this->request->isPost()) { |
||
| 66 | return; |
||
| 67 | } |
||
| 68 | $data = $this->request->getPost(); |
||
| 69 | $passwordCheckFail = $this->getSimplePasswords($data); |
||
| 70 | if(!empty($passwordCheckFail)){ |
||
| 71 | $this->view->message = [ |
||
| 72 | 'error' => $this->translation->_('gs_SetPasswordInfo') |
||
| 73 | ]; |
||
| 74 | } |
||
| 75 | if(!empty($passwordCheckFail)){ |
||
| 76 | $this->view->success = false; |
||
| 77 | $this->view->passwordCheckFail = $passwordCheckFail; |
||
| 78 | return; |
||
| 79 | } |
||
| 80 | |||
| 81 | $pbxSettings = PbxSettings::getDefaultArrayValues(); |
||
| 82 | if(isset($data['SSHPassword'])){ |
||
| 83 | // Если отправили пароль по-умолчанию, то сделаем его хэш равным хэш пароля WEB |
||
| 84 | if($data['SSHPassword'] === $pbxSettings['SSHPassword']){ |
||
| 85 | $data['SSHPasswordHash'] = md5($data['WebAdminPassword']); |
||
| 86 | }else{ |
||
| 87 | $data['SSHPasswordHash'] = md5($data['SSHPassword']); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | $this->db->begin(); |
||
| 91 | foreach ($pbxSettings as $key => $value) { |
||
| 92 | switch ($key) { |
||
| 93 | case 'PBXRecordCalls': |
||
| 94 | case 'AJAMEnabled': |
||
| 95 | case 'AMIEnabled': |
||
| 96 | case 'RestartEveryNight': |
||
| 97 | case 'RedirectToHttps': |
||
| 98 | case 'PBXSplitAudioThread': |
||
| 99 | case 'UseWebRTC': |
||
| 100 | case 'SSHDisablePasswordLogins': |
||
| 101 | case 'PBXAllowGuestCalls': |
||
| 102 | case '***ALL CHECK BOXES ABOVE***': |
||
| 103 | $newValue = ($data[$key] === 'on') ? '1' : '0'; |
||
| 104 | break; |
||
| 105 | case 'SSHPassword': |
||
| 106 | // Если отправили пароль по-умолчанию, то сделаем его равным паролю WEB |
||
| 107 | if ($data[$key] === $value) { |
||
| 108 | $newValue = $data['WebAdminPassword']; |
||
| 109 | } else { |
||
| 110 | $newValue = $data[$key]; |
||
| 111 | } |
||
| 112 | break; |
||
| 113 | case 'SendMetrics': |
||
| 114 | $newValue = ($data[$key] === 'on') ? '1' : '0'; |
||
| 115 | $this->session->set('SendMetrics', $newValue); |
||
| 116 | break; |
||
| 117 | case 'PBXFeatureTransferDigitTimeout': |
||
| 118 | $newValue = ceil((int)$data['PBXFeatureDigitTimeout']/1000); |
||
| 119 | break; |
||
| 120 | default: |
||
| 121 | $newValue = $data[$key]; |
||
| 122 | } |
||
| 123 | |||
| 124 | if (array_key_exists($key, $data)) { |
||
| 125 | $record = PbxSettings::findFirstByKey($key); |
||
| 126 | if ($record === null) { |
||
| 127 | $record = new PbxSettings(); |
||
| 128 | $record->key = $key; |
||
| 129 | $record->value = $newValue; |
||
| 130 | } elseif ($record->key === $key |
||
| 131 | && $record->value === $newValue) { |
||
| 132 | continue; |
||
| 133 | } |
||
| 134 | $record->value = $newValue; |
||
| 135 | |||
| 136 | if ($record->save() === false) { |
||
| 137 | $errors = $record->getMessages(); |
||
| 138 | $this->flash->warning(implode('<br>', $errors)); |
||
| 139 | $this->view->success = false; |
||
| 140 | $this->db->rollback(); |
||
| 141 | |||
| 142 | return; |
||
| 143 | } |
||
| 144 | } |
||
| 145 | } |
||
| 146 | |||
| 147 | $codecs = json_decode($data['codecs'], true); |
||
| 148 | foreach ($codecs as $codec){ |
||
| 149 | $record = Codecs::findFirstById($codec['codecId']); |
||
| 150 | $record->priority = $codec['priority']; |
||
| 151 | $record->disabled = $codec['disabled']===true?'1':'0'; |
||
| 152 | $record->update(); |
||
| 153 | } |
||
| 154 | |||
| 155 | $this->flash->success($this->translation->_('ms_SuccessfulSaved')); |
||
| 156 | $this->view->success = true; |
||
| 157 | $this->db->commit(); |
||
| 158 | } |
||
| 160 | } |