| Conditions | 14 |
| Paths | 720 |
| Total Lines | 68 |
| Code Lines | 41 |
| 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 |
||
| 105 | public function finalizeParameters(bool $configureRequestContext = true): bool |
||
| 106 | { |
||
| 107 | $yamlHelper = $this->getYamlHelper(); |
||
| 108 | $params = $this->decodeParameters($yamlHelper->getParameters()); |
||
| 109 | $this->variableApi->getAll(VariableApi::CONFIG); // forces initialization of API |
||
| 110 | $this->variableApi->set(VariableApi::CONFIG, 'language_i18n', $params['locale']); |
||
| 111 | // Set the System Identifier as a unique string. |
||
| 112 | if (!$this->variableApi->get(VariableApi::CONFIG, 'system_identifier')) { |
||
| 113 | $this->variableApi->set(VariableApi::CONFIG, 'system_identifier', str_replace('.', '', uniqid((string) (random_int(1000000000, 9999999999)), true))); |
||
| 114 | } |
||
| 115 | // add admin email as site email |
||
| 116 | $this->variableApi->set(VariableApi::CONFIG, 'adminmail', $params['email']); |
||
| 117 | |||
| 118 | // add remaining parameters and remove unneeded ones |
||
| 119 | unset($params['username'], $params['password'], $params['email'], $params['dbtabletype']); |
||
| 120 | $params['datadir'] = !empty($params['datadir']) ? $params['datadir'] : 'web/uploads'; |
||
| 121 | |||
| 122 | $RandomLibFactory = new Factory(); |
||
| 123 | $generator = $RandomLibFactory->getMediumStrengthGenerator(); |
||
| 124 | if (!isset($params['secret']) || ('ThisTokenIsNotSoSecretChangeIt' === $params['secret'])) { |
||
| 125 | $params['secret'] = $generator->generateString(50); |
||
| 126 | } |
||
| 127 | if (!isset($params['url_secret'])) { |
||
| 128 | $params['url_secret'] = $generator->generateString(10); |
||
| 129 | } |
||
| 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 | $startController = $this->variableApi->getSystemVar('startController'); |
||
| 152 | [$moduleName] = explode(':', $startController); |
||
| 153 | if (!$this->kernel->isBundle($moduleName)) { |
||
| 154 | // set the 'start' page information to empty to avoid missing module errors. |
||
| 155 | $this->variableApi->set(VariableApi::CONFIG, 'startController', ''); |
||
| 156 | $this->variableApi->set(VariableApi::CONFIG, 'startargs', ''); |
||
| 157 | } |
||
| 158 | |||
| 159 | // 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. |
||
| 160 | $defaultTheme = (string) $this->variableApi->getSystemVar('Default_Theme'); |
||
| 161 | if (!$this->kernel->isBundle($defaultTheme) && $this->kernel->isBundle('ZikulaBootstrapTheme')) { |
||
| 162 | $this->variableApi->set(VariableApi::CONFIG, 'Default_Theme', 'ZikulaBootstrapTheme'); |
||
| 163 | } |
||
| 164 | unset($params['upgrading']); |
||
| 165 | } |
||
| 166 | |||
| 167 | $yamlHelper->setParameters($params); |
||
| 168 | |||
| 169 | // clear the cache |
||
| 170 | $this->cacheClearer->clear('symfony.config'); |
||
| 171 | |||
| 172 | return true; |
||
| 173 | } |
||
| 213 |