| Conditions | 15 |
| Paths | 864 |
| Total Lines | 86 |
| 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 |
||
| 136 | protected function prepareView(): void |
||
| 137 | { |
||
| 138 | date_default_timezone_set(PbxSettings::getValueByKey('PBXTimezone')); |
||
| 139 | $this->view->PBXVersion = PbxSettings::getValueByKey('PBXVersion'); |
||
| 140 | $this->view->MetaTegHeadDescription=$this->translation->_('MetategHeadDescription'); |
||
| 141 | if ($this->session->has(SessionController::SESSION_ID)) { |
||
| 142 | $this->view->PBXLicense = PbxSettings::getValueByKey('PBXLicense'); |
||
| 143 | } else { |
||
| 144 | $this->view->PBXLicense = ''; |
||
| 145 | } |
||
| 146 | |||
| 147 | $this->view->WebAdminLanguage = PbxSettings::getValueByKey('WebAdminLanguage'); |
||
| 148 | $this->view->AvailableLanguages = json_encode($this->elements->getAvailableWebAdminLanguages()); |
||
| 149 | $this->view->submitMode = $this->session->get('SubmitMode')??'SaveSettings'; |
||
| 150 | |||
| 151 | // Allow anonymous statistics collection for JS code |
||
| 152 | if (PbxSettings::getValueByKey('SendMetrics') === '1') { |
||
| 153 | touch('/tmp/sendmetrics'); |
||
| 154 | $this->view->lastSentryEventId = SentrySdk::getCurrentHub()->getLastEventId(); |
||
| 155 | } else { |
||
| 156 | if (file_exists('/tmp/sendmetrics')) { |
||
| 157 | unlink('/tmp/sendmetrics'); |
||
| 158 | } |
||
| 159 | $this->view->lastSentryEventId = null; |
||
| 160 | } |
||
| 161 | |||
| 162 | $title = 'MikoPBX'; |
||
| 163 | switch ($this->actionName) { |
||
| 164 | case'index': |
||
| 165 | case'delete': |
||
| 166 | case'save': |
||
| 167 | case'modify': |
||
| 168 | case'*** WITHOUT ACTION ***': |
||
| 169 | $title .= '|' . $this->translation->_("Breadcrumb{$this->controllerName}"); |
||
| 170 | break; |
||
| 171 | default: |
||
| 172 | $title .= '|' . $this->translation->_("Breadcrumb{$this->controllerName}{$this->actionName}"); |
||
| 173 | } |
||
| 174 | Tag::setTitle($title); |
||
| 175 | $this->view->t = $this->translation; |
||
| 176 | $this->view->debugMode = $this->config->path('adminApplication.debugMode'); |
||
| 177 | $this->view->urlToLogo = $this->url->get('assets/img/logo-mikopbx.svg'); |
||
| 178 | $this->view->urlToWiki = "https://wiki.mikopbx.com/{$this->controllerNameUnCamelized}"; |
||
| 179 | if ($this->language === 'ru') { |
||
| 180 | $this->view->urlToSupport = 'https://www.mikopbx.ru/support/?fromPBX=true'; |
||
| 181 | } else { |
||
| 182 | $this->view->urlToSupport = 'https://www.mikopbx.com/support/?fromPBX=true'; |
||
| 183 | } |
||
| 184 | $this->view->urlToController = $this->url->get($this->controllerNameUnCamelized); |
||
| 185 | $this->view->represent = ''; |
||
| 186 | |||
| 187 | $isExternalModuleController = stripos($this->dispatcher->getNamespaceName(), '\\Module') === 0; |
||
| 188 | // We can disable module status toggle from module controller, using the showModuleStatusToggle variable |
||
| 189 | if (property_exists($this, 'showModuleStatusToggle')) { |
||
| 190 | $this->view->setVar('showModuleStatusToggle', $this->showModuleStatusToggle); |
||
| 191 | } else { |
||
| 192 | $this->view->setVar('showModuleStatusToggle', true); |
||
| 193 | } |
||
| 194 | |||
| 195 | // Add module variables into view |
||
| 196 | if ($isExternalModuleController) { |
||
| 197 | $moduleLinks = []; |
||
| 198 | /** @var PbxExtensionModules $module */ |
||
| 199 | $module = PbxExtensionModules::findFirstByUniqid($this->controllerName); |
||
| 200 | if ($module === null) { |
||
| 201 | $module = new PbxExtensionModules(); |
||
| 202 | $module->disabled = '1'; |
||
| 203 | $module->name = 'Unknown module'; |
||
| 204 | } else { |
||
| 205 | try { |
||
| 206 | $links = json_decode($module->wiki_links, true, 512, JSON_THROW_ON_ERROR); |
||
|
|
|||
| 207 | if (is_array($links)) { |
||
| 208 | $moduleLinks = $links; |
||
| 209 | } |
||
| 210 | } catch (\JsonException $e) { |
||
| 211 | Util::sysLogMsg(__CLASS__, $e->getMessage()); |
||
| 212 | } |
||
| 213 | } |
||
| 214 | $this->view->setVar('module', $module); |
||
| 215 | $this->customModuleWikiLinks($moduleLinks); |
||
| 216 | |||
| 217 | // If it is module we have to use another volt template |
||
| 218 | $this->view->setTemplateAfter('modules'); |
||
| 219 | } else { |
||
| 220 | $this->customWikiLinks(); |
||
| 221 | $this->view->setTemplateAfter('main'); |
||
| 222 | } |
||
| 334 |