| Conditions | 20 |
| Paths | 164 |
| Total Lines | 64 |
| Code Lines | 49 |
| 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 saveAction(): void |
||
| 41 | { |
||
| 42 | if ( ! $this->request->isPost()) { |
||
| 43 | return; |
||
| 44 | } |
||
| 45 | $data = $this->request->getPost(); |
||
| 46 | $pbxSettings = PbxSettings::getDefaultArrayValues(); |
||
| 47 | $this->db->begin(); |
||
| 48 | foreach ($pbxSettings as $key => $value) { |
||
| 49 | $record = PbxSettings::findFirstByKey($key); |
||
| 50 | if ($record === null) { |
||
| 51 | $record = new PbxSettings(); |
||
| 52 | $record->key = $key; |
||
| 53 | $record->value = $value; |
||
| 54 | } |
||
| 55 | |||
| 56 | switch ($key) { |
||
| 57 | case 'PBXRecordCalls': |
||
| 58 | case 'AJAMEnabled': |
||
| 59 | case 'AMIEnabled': |
||
| 60 | case 'RestartEveryNight': |
||
| 61 | case 'RedirectToHttps': |
||
| 62 | case 'PBXSplitAudioThread': |
||
| 63 | case '***ALL CHECK BOXES ABOVE***': |
||
| 64 | $record->value = ($data[$key] === 'on') ? '1' : '0'; |
||
| 65 | break; |
||
| 66 | case 'SSHPassword': |
||
| 67 | //Если отправили пароль по-умолчанию, то сделаем его равным паролю WEB |
||
| 68 | if ($data[$key] === $pbxSettings[$key]) { |
||
| 69 | $record->value = $data['WebAdminPassword']; |
||
| 70 | } else { |
||
| 71 | $record->value = $data[$key]; |
||
| 72 | } |
||
| 73 | break; |
||
| 74 | case 'SendMetrics': |
||
| 75 | $record->value = ($data[$key] === 'on') ? '1' : '0'; |
||
| 76 | $this->session->set('SendMetrics', $record->value); |
||
| 77 | break; |
||
| 78 | default: |
||
| 79 | if (array_key_exists($key, $data)) { |
||
| 80 | $record->value = $data[$key]; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | if ($record->save() === false) { |
||
| 84 | $errors = $record->getMessages(); |
||
| 85 | $this->flash->warning(implode('<br>', $errors)); |
||
| 86 | $this->view->success = false; |
||
| 87 | $this->db->rollback(); |
||
| 88 | |||
| 89 | return; |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | $codecs = json_decode($data['codecs'], true); |
||
| 94 | foreach ($codecs as $codec){ |
||
| 95 | $record = Codecs::findFirstById($codec['codecId']); |
||
| 96 | $record->priority = $codec['priority']; |
||
| 97 | $record->disabled = $codec['disabled']===true?'1':'0'; |
||
| 98 | $record->update(); |
||
| 99 | } |
||
| 100 | |||
| 101 | $this->flash->success($this->translation->_('ms_SuccessfulSaved')); |
||
| 102 | $this->view->success = true; |
||
| 103 | $this->db->commit(); |
||
| 104 | } |
||
| 106 | } |