| Conditions | 18 |
| Paths | 1728 |
| Total Lines | 91 |
| Code Lines | 69 |
| 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 |
||
| 137 | protected function prepareView(): void |
||
| 138 | { |
||
| 139 | date_default_timezone_set($this->getSessionData('PBXTimezone')); |
||
| 140 | $roSession = $this->sessionRO; |
||
| 141 | $this->view->PBXVersion = $this->getSessionData('PBXVersion'); |
||
| 142 | if ($roSession !== null && array_key_exists('auth', $roSession)) { |
||
| 143 | $this->view->SSHPort = $this->getSessionData('SSHPort'); |
||
| 144 | $this->view->PBXLicense = $this->getSessionData('PBXLicense'); |
||
| 145 | } else { |
||
| 146 | $this->view->SSHPort = ''; |
||
| 147 | $this->view->PBXLicense = ''; |
||
| 148 | } |
||
| 149 | // Кеш версий модулей и атс, для правильной работы АТС при установке модулей |
||
| 150 | $versionHash = $this->getVersionsHash(); |
||
| 151 | $this->session->set('versionHash', $versionHash); |
||
| 152 | |||
| 153 | $this->view->WebAdminLanguage = $this->getSessionData('WebAdminLanguage'); |
||
| 154 | $this->view->AvailableLanguages = json_encode($this->elements->getAvailableWebAdminLanguages()); |
||
| 155 | |||
| 156 | if ($roSession !== null && array_key_exists('SubmitMode', $roSession)) { |
||
| 157 | $this->view->submitMode = $roSession['SubmitMode']; |
||
| 158 | } else { |
||
| 159 | $this->view->submitMode = 'SaveSettings'; |
||
| 160 | } |
||
| 161 | |||
| 162 | // Добавим версию модуля, если это модуль |
||
| 163 | $moduleLinks = []; |
||
| 164 | if ($this->moduleName === 'PBXExtension') { |
||
| 165 | /** @var PbxExtensionModules $module */ |
||
| 166 | $module = PbxExtensionModules::findFirstByUniqid($this->controllerName); |
||
| 167 | if ($module === null) { |
||
| 168 | $module = new PbxExtensionModules(); |
||
| 169 | $module->disabled = '1'; |
||
| 170 | $module->name = 'Unknown module'; |
||
| 171 | }else{ |
||
| 172 | try { |
||
| 173 | $links = json_decode($module->wiki_links, true, 512, JSON_THROW_ON_ERROR); |
||
|
|
|||
| 174 | if(is_array($links)){ |
||
| 175 | $moduleLinks = $links; |
||
| 176 | } |
||
| 177 | }catch (\JsonException $e){ |
||
| 178 | Util::sysLogMsg(__CLASS__, $e->getMessage()); |
||
| 179 | } |
||
| 180 | } |
||
| 181 | $this->view->module = $module; |
||
| 182 | } |
||
| 183 | |||
| 184 | // Разрешим отправку анонимной информации об ошибках |
||
| 185 | if ($this->getSessionData('SendMetrics') === '1') { |
||
| 186 | touch('/tmp/sendmetrics'); |
||
| 187 | $this->view->lastSentryEventId = SentrySdk::getCurrentHub()->getLastEventId(); |
||
| 188 | } else { |
||
| 189 | if (file_exists('/tmp/sendmetrics')) { |
||
| 190 | unlink('/tmp/sendmetrics'); |
||
| 191 | } |
||
| 192 | $this->view->lastSentryEventId = null; |
||
| 193 | } |
||
| 194 | $title = 'MikoPBX'; |
||
| 195 | switch ($this->actionName) { |
||
| 196 | case'index': |
||
| 197 | case'delete': |
||
| 198 | case'save': |
||
| 199 | case'modify': |
||
| 200 | case'*** WITHOUT ACTION ***': |
||
| 201 | $title .= '|'. $this->translation->_("Breadcrumb{$this->controllerName}"); |
||
| 202 | break; |
||
| 203 | default: |
||
| 204 | $title .= '|'. $this->translation->_("Breadcrumb{$this->controllerName}{$this->actionName}"); |
||
| 205 | } |
||
| 206 | Tag::setTitle($title); |
||
| 207 | $this->view->t = $this->translation; |
||
| 208 | $this->view->debugMode = $this->config->path('adminApplication.debugMode'); |
||
| 209 | $this->view->urlToLogo = $this->url->get('assets/img/logo-mikopbx.svg'); |
||
| 210 | if ($this->language === 'ru') { |
||
| 211 | $this->view->urlToWiki = "https://wiki.mikopbx.com/{$this->controllerNameUnCamelized}"; |
||
| 212 | $this->view->urlToSupport = 'https://www.mikopbx.ru/support/?fromPBX=true'; |
||
| 213 | } else { |
||
| 214 | $this->view->urlToWiki = "https://wiki.mikopbx.com/{$this->language}:{$this->controllerNameUnCamelized}"; |
||
| 215 | $this->view->urlToSupport = 'https://www.mikopbx.com/support/?fromPBX=true'; |
||
| 216 | } |
||
| 217 | $this->view->urlToController = $this->url->get($this->controllerNameUnCamelized); |
||
| 218 | $this->view->represent = ''; |
||
| 219 | $this->view->cacheName = "{$this->controllerName}{$this->actionName}{$this->language}{$versionHash}"; |
||
| 220 | |||
| 221 | // If it is module we have to use another template |
||
| 222 | if ($this->moduleName === 'PBXExtension') { |
||
| 223 | $this->customModuleWikiLinks($moduleLinks); |
||
| 224 | $this->view->setTemplateAfter('modules'); |
||
| 225 | } else { |
||
| 226 | $this->customWikiLinks(); |
||
| 227 | $this->view->setTemplateAfter('main'); |
||
| 228 | } |
||
| 374 |