| Conditions | 11 |
| Paths | 162 |
| Total Lines | 56 |
| Code Lines | 31 |
| 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 |
||
| 126 | public function finalizeParameters(bool $configureRequestContext = true): bool |
||
| 127 | { |
||
| 128 | $yamlHelper = $this->getYamlHelper(); |
||
| 129 | $params = $this->decodeParameters($yamlHelper->getParameters()); |
||
| 130 | |||
| 131 | $this->variableApi->getAll(VariableApi::CONFIG); // forces initialization of API |
||
| 132 | if (!isset($params['upgrading'])) { |
||
| 133 | $this->variableApi->set(VariableApi::CONFIG, 'locale', $params['locale']); |
||
| 134 | // Set the System Identifier as a unique string. |
||
| 135 | if (!$this->variableApi->get(VariableApi::CONFIG, 'system_identifier')) { |
||
| 136 | $this->variableApi->set(VariableApi::CONFIG, 'system_identifier', str_replace('.', '', uniqid((string) (random_int(1000000000, 9999999999)), true))); |
||
| 137 | } |
||
| 138 | // add admin email as site email |
||
| 139 | $this->variableApi->set(VariableApi::CONFIG, 'adminmail', $params['email']); |
||
| 140 | $this->setMailerData($params); |
||
| 141 | } |
||
| 142 | |||
| 143 | $params = array_diff_key($params, array_flip($this->encodedParameterNames)); // remove all encoded params |
||
| 144 | $params['datadir'] = !empty($params['datadir']) ? $params['datadir'] : 'public/uploads'; |
||
| 145 | |||
| 146 | if ($configureRequestContext) { |
||
| 147 | // Configure the Request Context |
||
| 148 | // see http://symfony.com/doc/current/cookbook/console/sending_emails.html#configuring-the-request-context-globally |
||
| 149 | $request = $this->requestStack->getMasterRequest(); |
||
| 150 | $hostFromRequest = isset($request) ? $request->getHost() : null; |
||
| 151 | $schemeFromRequest = isset($request) ? $request->getScheme() : 'http'; |
||
| 152 | $basePathFromRequest = isset($request) ? $request->getBasePath() : null; |
||
| 153 | $params['router.request_context.host'] = $params['router.request_context.host'] ?? $hostFromRequest; |
||
| 154 | $params['router.request_context.scheme'] = $params['router.request_context.scheme'] ?? $schemeFromRequest; |
||
| 155 | $params['router.request_context.base_url'] = $params['router.request_context.base_url'] ?? $basePathFromRequest; |
||
| 156 | } |
||
| 157 | // store the recent version in a config var for later usage. This enables us to determine the version we are upgrading from |
||
| 158 | $this->variableApi->set(VariableApi::CONFIG, 'Version_Num', ZikulaKernel::VERSION); |
||
| 159 | |||
| 160 | if (isset($params['upgrading'])) { |
||
| 161 | $params['zikula_asset_manager.combine'] = false; |
||
| 162 | |||
| 163 | // unset start page information to avoid missing module errors |
||
| 164 | $this->variableApi->set(VariableApi::CONFIG, 'startController_en', ''); |
||
| 165 | |||
| 166 | // 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. |
||
| 167 | $defaultTheme = (string) $this->variableApi->getSystemVar('Default_Theme'); |
||
| 168 | if (!$this->kernel->isBundle($defaultTheme) && $this->kernel->isBundle('ZikulaBootstrapTheme')) { |
||
| 169 | $this->variableApi->set(VariableApi::CONFIG, 'Default_Theme', 'ZikulaBootstrapTheme'); |
||
| 170 | } |
||
| 171 | } else { |
||
| 172 | $this->writeEnvVars(); |
||
| 173 | } |
||
| 174 | |||
| 175 | // write parameters into config/services_custom.yaml |
||
| 176 | $yamlHelper->setParameters($params); |
||
| 177 | |||
| 178 | // clear the cache |
||
| 179 | $this->cacheClearer->clear('symfony.config'); |
||
| 180 | |||
| 181 | return true; |
||
| 182 | } |
||
| 239 |