Conditions | 12 |
Paths | 324 |
Total Lines | 60 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 1 | 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 |
||
111 | public function finalizeParameters(bool $configureRequestContext = true): bool |
||
112 | { |
||
113 | $yamlHelper = $this->getYamlHelper(); |
||
114 | $params = $this->decodeParameters($yamlHelper->getParameters()); |
||
115 | |||
116 | $this->variableApi->getAll(VariableApi::CONFIG); // forces initialization of API |
||
117 | if (!isset($params['upgrading'])) { |
||
118 | $this->variableApi->set(VariableApi::CONFIG, 'locale', $params['locale']); |
||
119 | // Set the System Identifier as a unique string. |
||
120 | if (!$this->variableApi->get(VariableApi::CONFIG, 'system_identifier')) { |
||
121 | $this->variableApi->set(VariableApi::CONFIG, 'system_identifier', str_replace('.', '', uniqid((string) (random_int(1000000000, 9999999999)), true))); |
||
122 | } |
||
123 | // add admin email as site email |
||
124 | $this->variableApi->set(VariableApi::CONFIG, 'adminmail', $params['email']); |
||
125 | } |
||
126 | |||
127 | // add remaining parameters and remove unneeded ones |
||
128 | unset($params['username'], $params['password'], $params['email']); |
||
129 | $params['datadir'] = !empty($params['datadir']) ? $params['datadir'] : 'public/uploads'; |
||
130 | |||
131 | if ($configureRequestContext) { |
||
132 | // Configure the Request Context |
||
133 | // see http://symfony.com/doc/current/cookbook/console/sending_emails.html#configuring-the-request-context-globally |
||
134 | $request = $this->requestStack->getMasterRequest(); |
||
135 | $hostFromRequest = isset($request) ? $request->getHost() : null; |
||
136 | $schemeFromRequest = isset($request) ? $request->getScheme() : 'http'; |
||
137 | $basePathFromRequest = isset($request) ? $request->getBasePath() : null; |
||
138 | $params['router.request_context.host'] = $params['router.request_context.host'] ?? $hostFromRequest; |
||
139 | $params['router.request_context.scheme'] = $params['router.request_context.scheme'] ?? $schemeFromRequest; |
||
140 | $params['router.request_context.base_url'] = $params['router.request_context.base_url'] ?? $basePathFromRequest; |
||
141 | } |
||
142 | // store the recent version in a config var for later usage. This enables us to determine the version we are upgrading from |
||
143 | $this->variableApi->set(VariableApi::CONFIG, 'Version_Num', ZikulaKernel::VERSION); |
||
144 | |||
145 | if (isset($params['upgrading'])) { |
||
146 | $params['zikula_asset_manager.combine'] = false; |
||
147 | |||
148 | // unset start page information to avoid missing module errors |
||
149 | $this->variableApi->set(VariableApi::CONFIG, 'startController_en', ''); |
||
150 | |||
151 | // on upgrade, if a user doesn't add their custom theme back to the /theme dir, it should be reset to a core theme, if available. |
||
152 | $defaultTheme = (string) $this->variableApi->getSystemVar('Default_Theme'); |
||
153 | if (!$this->kernel->isBundle($defaultTheme) && $this->kernel->isBundle('ZikulaBootstrapTheme')) { |
||
154 | $this->variableApi->set(VariableApi::CONFIG, 'Default_Theme', 'ZikulaBootstrapTheme'); |
||
155 | } |
||
156 | } |
||
157 | |||
158 | // write parameters into config/services_custom.yaml |
||
159 | $yamlHelper->setParameters($params); |
||
160 | |||
161 | if (isset($params['upgrading'])) { |
||
162 | unset($params['upgrading']); |
||
163 | } else { |
||
164 | $this->writeEnvVars(); |
||
165 | } |
||
166 | |||
167 | // clear the cache |
||
168 | $this->cacheClearer->clear('symfony.config'); |
||
169 | |||
170 | return true; |
||
171 | } |
||
205 |