| Conditions | 16 |
| Paths | 864 |
| Total Lines | 85 |
| Code Lines | 64 |
| 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 |
||
| 89 | protected function prepareView(): void |
||
| 90 | { |
||
| 91 | date_default_timezone_set($this->getSessionData('PBXTimezone')); |
||
| 92 | $roSession = $this->sessionRO; |
||
| 93 | $this->view->PBXVersion = $this->getSessionData('PBXVersion'); |
||
| 94 | if ($roSession !== null && array_key_exists('auth', $roSession)) { |
||
| 95 | $this->view->SSHPort = $this->getSessionData('SSHPort'); |
||
| 96 | $this->view->PBXLicense = $this->getSessionData('PBXLicense'); |
||
| 97 | } else { |
||
| 98 | $this->view->SSHPort = ''; |
||
| 99 | $this->view->PBXLicense = ''; |
||
| 100 | } |
||
| 101 | // Кеш версий модулей и атс, для правильной работы АТС при установке модулей |
||
| 102 | $versionHash = $this->getVersionsHash(); |
||
| 103 | $this->session->set('versionHash', $versionHash); |
||
| 104 | |||
| 105 | $this->view->WebAdminLanguage = $this->getSessionData('WebAdminLanguage'); |
||
| 106 | $this->view->AvailableLanguages = json_encode($this->elements->getAvailableWebAdminLanguages()); |
||
| 107 | |||
| 108 | if ($roSession !== null && array_key_exists('SubmitMode', $roSession)) { |
||
| 109 | $this->view->submitMode = $roSession['SubmitMode']; |
||
| 110 | } else { |
||
| 111 | $this->view->submitMode = 'SaveSettings'; |
||
| 112 | } |
||
| 113 | |||
| 114 | // Добавим версию модуля, если это модуль |
||
| 115 | if ($this->moduleName === 'PBXExtension') { |
||
| 116 | $module = PbxExtensionModules::findFirstByUniqid($this->controllerName); |
||
| 117 | if ($module === null) { |
||
| 118 | $module = new PbxExtensionModules(); |
||
| 119 | $module->disabled = '1'; |
||
| 120 | $module->name = 'Unknown module'; |
||
| 121 | } |
||
| 122 | $this->view->module = $module; |
||
| 123 | } |
||
| 124 | |||
| 125 | // Разрешим отправку анонимной информации об ошибках |
||
| 126 | if ($this->getSessionData('SendMetrics') === '1') { |
||
| 127 | touch('/tmp/sendmetrics'); |
||
| 128 | $this->view->lastSentryEventId = SentrySdk::getCurrentHub()->getLastEventId(); |
||
| 129 | } else { |
||
| 130 | if (file_exists('/tmp/sendmetrics')) { |
||
| 131 | unlink('/tmp/sendmetrics'); |
||
| 132 | } |
||
| 133 | $this->view->lastSentryEventId = null; |
||
| 134 | } |
||
| 135 | $title = 'MikoPBX'; |
||
| 136 | switch ($this->actionName) { |
||
| 137 | case'index': |
||
| 138 | case'delete': |
||
| 139 | case'save': |
||
| 140 | case'modify': |
||
| 141 | case'*** WITHOUT ACTION ***': |
||
| 142 | $title .= '|'. $this->translation->_("Breadcrumb{$this->controllerName}"); |
||
| 143 | break; |
||
| 144 | default: |
||
| 145 | $title .= '|'. $this->translation->_("Breadcrumb{$this->controllerName}{$this->actionName}"); |
||
| 146 | } |
||
| 147 | Tag::setTitle($title); |
||
| 148 | $this->view->t = $this->translation; |
||
| 149 | $this->view->debugMode = $this->config->path('adminApplication.debugMode'); |
||
| 150 | $this->view->urlToLogo = $this->url->get('assets/img/logo-mikopbx.svg'); |
||
| 151 | if ($this->language === 'ru') { |
||
| 152 | $this->view->urlToWiki |
||
| 153 | = "https://wiki.mikopbx.com/{$this->controllerNameUnCamelized}"; |
||
| 154 | $this->view->urlToSupport |
||
| 155 | = 'https://www.mikopbx.ru/support/?fromPBX=true'; |
||
| 156 | } else { |
||
| 157 | $this->view->urlToWiki |
||
| 158 | = "https://wiki.mikopbx.com/{$this->language}:{$this->controllerNameUnCamelized}"; |
||
| 159 | $this->view->urlToSupport |
||
| 160 | = 'https://www.mikopbx.com/support/?fromPBX=true'; |
||
| 161 | } |
||
| 162 | |||
| 163 | $this->customWikiLinks(); |
||
| 164 | |||
| 165 | $this->view->urlToController = $this->url->get($this->controllerNameUnCamelized); |
||
| 166 | $this->view->represent = ''; |
||
| 167 | $this->view->cacheName = "{$this->controllerName}{$this->actionName}{$this->language}{$versionHash}"; |
||
| 168 | |||
| 169 | // If it is module we have to use another template |
||
| 170 | if ($this->moduleName === 'PBXExtension') { |
||
| 171 | $this->view->setTemplateAfter('modules'); |
||
| 172 | } else { |
||
| 173 | $this->view->setTemplateAfter('main'); |
||
| 174 | } |
||
| 321 |