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