| Conditions | 12 |
| Paths | 324 |
| Total Lines | 64 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 | $params['umask'] = $params['umask'] ?? null; |
||
| 143 | $params['installed'] = true; |
||
| 144 | // set currently installed version into parameters |
||
| 145 | $params[ZikulaKernel::CORE_INSTALLED_VERSION_PARAM] = ZikulaKernel::VERSION; |
||
| 146 | // store the recent version in a config var for later usage. This enables us to determine the version we are upgrading from |
||
| 147 | $this->variableApi->set(VariableApi::CONFIG, 'Version_Num', ZikulaKernel::VERSION); |
||
| 148 | |||
| 149 | if (isset($params['upgrading'])) { |
||
| 150 | $params['zikula_asset_manager.combine'] = false; |
||
| 151 | |||
| 152 | // unset start page information to avoid missing module errors |
||
| 153 | $this->variableApi->set(VariableApi::CONFIG, 'startController_en', ''); |
||
| 154 | |||
| 155 | // 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. |
||
| 156 | $defaultTheme = (string) $this->variableApi->getSystemVar('Default_Theme'); |
||
| 157 | if (!$this->kernel->isBundle($defaultTheme) && $this->kernel->isBundle('ZikulaBootstrapTheme')) { |
||
| 158 | $this->variableApi->set(VariableApi::CONFIG, 'Default_Theme', 'ZikulaBootstrapTheme'); |
||
| 159 | } |
||
| 160 | } |
||
| 161 | |||
| 162 | // write parameters into config/services_custom.yaml |
||
| 163 | $yamlHelper->setParameters($params); |
||
| 164 | |||
| 165 | if (isset($params['upgrading'])) { |
||
| 166 | unset($params['upgrading']); |
||
| 167 | } else { |
||
| 168 | $this->writeEnvVars(); |
||
| 169 | } |
||
| 170 | |||
| 171 | // clear the cache |
||
| 172 | $this->cacheClearer->clear('symfony.config'); |
||
| 173 | |||
| 174 | return true; |
||
| 175 | } |
||
| 245 |