Conditions | 19 |
Paths | 2592 |
Total Lines | 92 |
Code Lines | 69 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
44 | protected function prepareView() :void{ |
||
45 | date_default_timezone_set( $this->getSessionData('PBXTimezone') ); |
||
46 | $roSession = $this->sessionRO; |
||
47 | $this->view->PBXVersion = $this->getSessionData('PBXVersion'); |
||
48 | if ( $roSession !== null && array_key_exists('auth', $roSession)) { |
||
49 | $this->view->SSHPort = $this->getSessionData('SSHPort'); |
||
50 | $this->view->PBXLicense = $this->getSessionData('PBXLicense'); |
||
51 | $this->view->PBXLanguage= $this->getSessionData('PBXLanguage'); |
||
52 | } else { |
||
53 | $this->view->SSHPort = ''; |
||
54 | $this->view->PBXLicense = ''; |
||
55 | $this->view->PBXLanguage= ''; |
||
56 | } |
||
57 | |||
58 | // Кеш версий модулей и атс, для правильной работы АТС при установке модулей |
||
59 | $versionHash = $this->getVersionsHash(); |
||
60 | $this->session->set( 'versionHash', $versionHash); |
||
61 | |||
62 | if ( $roSession !== null && array_key_exists('SubmitMode', $roSession)) { |
||
63 | $this->view->submitMode = $roSession[ 'SubmitMode' ]; |
||
64 | } else { |
||
65 | $this->view->submitMode = 'SaveSettings'; |
||
66 | } |
||
67 | |||
68 | // Добавим версию модуля, если это модуль |
||
69 | if ( $this->moduleName === 'PBXExtension' ) { |
||
70 | $module = PbxExtensionModules::findFirstByUniqid( $this->controllerName ); |
||
71 | if ( !$module ) { |
||
72 | $module = new PbxExtensionModules(); |
||
73 | $module->disabled = '1'; |
||
74 | $module->name = 'Unknown module'; |
||
75 | } |
||
76 | $this->view->module = $module; |
||
77 | } |
||
78 | |||
79 | // Разрешим отправку анонимной информации об ошибках |
||
80 | if ($this->getSessionData('SendMetrics') === '1'){ |
||
81 | touch('/tmp/sendmetrics'); |
||
82 | $this->view->lastSentryEventId = Sentry\State\Hub::getCurrent()->getLastEventId(); |
||
83 | } else { |
||
84 | if (file_exists('/tmp/sendmetrics')){ |
||
85 | unlink('/tmp/sendmetrics'); |
||
86 | } |
||
87 | $this->view->lastSentryEventId = Null; |
||
88 | } |
||
89 | switch ( $this->actionName ) { |
||
90 | case'index': |
||
91 | case'delete': |
||
92 | case'save': |
||
93 | case'modify': |
||
94 | case'*** WITHOUT ACTION ***': |
||
95 | $this->tag->setTitle( $this->config->application->kind . ' | ' |
||
96 | . $this->translation->_( 'Breadcrumb' |
||
97 | . $this->controllerName ) ); |
||
98 | break; |
||
99 | default: |
||
100 | $this->tag->setTitle( $this->config->application->kind . ' | ' |
||
101 | . $this->translation->_( 'Breadcrumb' |
||
102 | . $this->controllerName |
||
103 | . $this->actionName ) ); |
||
104 | } |
||
105 | |||
106 | $this->view->t = $this->translation; |
||
107 | $this->view->debugMode = $this->config->application->debugMode; |
||
108 | $this->view->urlToLogo = $this->url->get( 'public/img/logo-mikopbx.svg' ); |
||
109 | if ($this->language === 'ru'){ |
||
110 | $this->view->urlToWiki |
||
111 | = "https://wiki.mikopbx.com/{$this->controllerNameUnCamelized}"; |
||
112 | } else { |
||
113 | $this->view->urlToWiki |
||
114 | = "https://wiki.mikopbx.com/{$this->language}:{$this->controllerNameUnCamelized}"; |
||
115 | } |
||
116 | |||
117 | $this->view->urlToController = $this->url->get( $this->controllerNameUnCamelized ); |
||
118 | $this->view->represent = ''; |
||
119 | $this->view->cacheName = "{$this->controllerName}{$this->actionName}{$this->language}{$versionHash}"; |
||
120 | |||
121 | // Подключим нужный View |
||
122 | if ( $this->moduleName === 'PBXExtension' ) { |
||
123 | $this->view->setTemplateAfter( 'modules' ); |
||
124 | } else { |
||
125 | $this->view->setTemplateAfter( 'main' ); |
||
126 | } |
||
127 | |||
128 | // Для модулей кинем в кеш все статические картинки |
||
129 | if ( $this->moduleName === 'PBXExtension' ) { |
||
130 | $modulesDir = $this->getDI()->getModulesDir(); |
||
131 | $moduleImageDir = $modulesDir . $this->controllerName.'/public/img'; |
||
132 | $moduleImageCacheDir = $this->config->application->imgCacheDir.$this->controllerName; |
||
133 | if (file_exists($moduleImageDir) |
||
134 | && !file_exists($moduleImageCacheDir)){ |
||
135 | symlink ( $moduleImageDir, $moduleImageCacheDir ); |
||
136 | } |
||
324 |