| Total Complexity | 50 |
| Total Lines | 300 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like ProvidersController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ProvidersController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | class ProvidersController extends BaseController |
||
| 16 | { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Получение общего списка провайдеров |
||
| 20 | */ |
||
| 21 | public function indexAction(): void |
||
| 40 | } |
||
| 41 | |||
| 42 | |||
| 43 | /** |
||
| 44 | * Открытие карточки SIP провайдера и заполнение значений по умолчанию |
||
| 45 | * |
||
| 46 | * @param string $uniqid Уникальный идентификатор провайдера, если мы открываем существующего |
||
| 47 | */ |
||
| 48 | public function modifysipAction(string $uniqid = ''): void |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Открытие карточки IAX провайдера и заполнение значений по умолчанию |
||
| 73 | * |
||
| 74 | * @param string $uniqid Уникальный идентификатор провайдера, если мы открываем существующего |
||
| 75 | */ |
||
| 76 | public function modifyiaxAction(string $uniqid = ''): void |
||
| 94 | } |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Включение провайдера |
||
| 98 | * |
||
| 99 | * @param string $type тип провайдера SIP или IAX |
||
| 100 | * @param string $uniqid Уникальный идентификатор провайдера, если мы открываем существующего |
||
| 101 | */ |
||
| 102 | public function enableAction(string $type, string $uniqid = ''): void |
||
| 103 | { |
||
| 104 | $this->view->success = false; |
||
| 105 | switch ($type) { |
||
| 106 | case 'iax': |
||
| 107 | { |
||
| 108 | $provider = Iax::findFirstByUniqid($uniqid); |
||
| 109 | break; |
||
| 110 | } |
||
| 111 | case 'sip': |
||
| 112 | { |
||
| 113 | $provider = Sip::findFirstByUniqid($uniqid); |
||
| 114 | break; |
||
| 115 | } |
||
| 116 | default: |
||
| 117 | $provider = null; |
||
| 118 | } |
||
| 119 | if ($provider !== null) { |
||
| 120 | $provider->disabled = '0'; |
||
| 121 | if ($provider->save() === true) { |
||
| 122 | $this->view->success = true; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Отключение провайдера |
||
| 129 | * |
||
| 130 | * @param string $type тип провайдера SIP или IAX |
||
| 131 | * @param string $uniqid Уникальный идентификатор провайдера, если мы открываем существующего |
||
| 132 | */ |
||
| 133 | public function disableAction(string $type, string $uniqid = ''): void |
||
| 134 | { |
||
| 135 | $this->view->success = false; |
||
| 136 | switch ($type) { |
||
| 137 | case 'iax': |
||
| 138 | { |
||
| 139 | $provider = Iax::findFirstByUniqid($uniqid); |
||
| 140 | break; |
||
| 141 | } |
||
| 142 | case 'sip': |
||
| 143 | { |
||
| 144 | $provider = Sip::findFirstByUniqid($uniqid); |
||
| 145 | break; |
||
| 146 | } |
||
| 147 | default: |
||
| 148 | $provider = null; |
||
| 149 | } |
||
| 150 | if ($provider !== null) { |
||
| 151 | $provider->disabled = '1'; |
||
| 152 | if ($provider->save() === true) { |
||
| 153 | $this->view->success = true; |
||
| 154 | } |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Сохранение провайдера AJAX запросом из формы |
||
| 160 | * |
||
| 161 | * @param string $type - sip или iax |
||
| 162 | * |
||
| 163 | */ |
||
| 164 | public function saveAction(string $type): void |
||
| 187 | } |
||
| 188 | } |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Сохранение параметров в таблицу Providers |
||
| 192 | * |
||
| 193 | * @param array $data - POST дата |
||
| 194 | * @param string $type - sip или iax |
||
| 195 | * |
||
| 196 | * @return bool результат сохранения |
||
| 197 | */ |
||
| 198 | private function saveProvider(array $data, string $type): bool |
||
| 271 | } |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Удаление провайдера |
||
| 275 | * |
||
| 276 | * @param string $uniqid Уникальный идентификатор провайдера |
||
| 277 | */ |
||
| 278 | public function deleteAction(string $uniqid = ''): void |
||
| 315 | } |
||
| 316 | |||
| 317 | } |