| Conditions | 6 |
| Paths | 7 |
| Total Lines | 72 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 125 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 126 | { |
||
| 127 | if (version_compare($this->currentInstalledVersion, UpgraderController::ZIKULACORE_MINIMUM_UPGRADE_VERSION, '<')) { |
||
| 128 | $output->writeln($this->translator->__f('The current installed version of Zikula is reporting (%1$s). You must upgrade to version (%2$s) before you can use this upgrade.', ['%1$s' => $this->currentInstalledVersion, '%2$s' => UpgraderController::ZIKULACORE_MINIMUM_UPGRADE_VERSION])); |
||
| 129 | |||
| 130 | return 1; |
||
| 131 | } |
||
| 132 | |||
| 133 | $io = new SymfonyStyle($input, $output); |
||
| 134 | $io->title($this->translator->__('Zikula Upgrader Script')); |
||
| 135 | $io->section($this->translator->__f('*** UPGRADING TO ZIKULA CORE %version% ***', ['%version%' => ZikulaKernel::VERSION])); |
||
| 136 | $io->text($this->translator->__f('Upgrading Zikula in %env% environment.', ['%env%' => $this->kernel->getEnvironment()])); |
||
| 137 | |||
| 138 | $warnings = $this->controllerHelper->initPhp(); |
||
| 139 | if (!empty($warnings)) { |
||
| 140 | $this->printWarnings($output, $warnings); |
||
| 141 | |||
| 142 | return 2; |
||
| 143 | } |
||
| 144 | $checks = $this->controllerHelper->requirementsMet(); |
||
| 145 | if (true !== $checks) { |
||
|
|
|||
| 146 | $this->printRequirementsWarnings($output, $checks); |
||
| 147 | |||
| 148 | return 2; |
||
| 149 | } |
||
| 150 | |||
| 151 | $this->migrateUsers($io, $output); |
||
| 152 | |||
| 153 | // avoid warning in PHP 7.2 based on ini_set() usage which is caused by any access to the |
||
| 154 | // session before regeneration happens (e.g. by an event listener executed before a login) |
||
| 155 | // see issue #3898 for the details |
||
| 156 | $reportingLevel = error_reporting(); |
||
| 157 | error_reporting($reportingLevel & ~E_WARNING); |
||
| 158 | |||
| 159 | // get the settings from user input |
||
| 160 | $settings = $this->getHelper('form')->interactUsingForm(LocaleType::class, $input, $output, [ |
||
| 161 | 'choices' => $this->localeApi->getSupportedLocaleNames(), |
||
| 162 | 'choice_loader' => null |
||
| 163 | ]); |
||
| 164 | |||
| 165 | $data = $this->getHelper('form')->interactUsingForm(LoginType::class, $input, $output); |
||
| 166 | foreach ($data as $k => $v) { |
||
| 167 | $data[$k] = base64_encode($v); // encode so values are 'safe' for json |
||
| 168 | } |
||
| 169 | $settings = array_merge($settings, $data); |
||
| 170 | |||
| 171 | $data = $this->getHelper('form')->interactUsingForm(RequestContextType::class, $input, $output); |
||
| 172 | foreach ($data as $k => $v) { |
||
| 173 | $newKey = str_replace(':', '.', $k); |
||
| 174 | $data[$newKey] = $v; |
||
| 175 | unset($data[$k]); |
||
| 176 | } |
||
| 177 | $settings = array_merge($settings, $data); |
||
| 178 | |||
| 179 | $this->printSettings($settings, $io); |
||
| 180 | $io->newLine(); |
||
| 181 | |||
| 182 | // write the parameters to custom_parameters.yml |
||
| 183 | $yamlManager = new YamlDumper($this->kernel->getProjectDir() . '/app/config', 'custom_parameters.yml'); |
||
| 184 | $params = array_merge($yamlManager->getParameters(), $settings); |
||
| 185 | unset($params['upgrading']); |
||
| 186 | $yamlManager->setParameters($params); |
||
| 187 | |||
| 188 | // upgrade! |
||
| 189 | $ajaxStage = new AjaxUpgraderStage($this->translator, $this->params); |
||
| 190 | $this->stageHelper->handleAjaxStage($ajaxStage, $io); |
||
| 191 | |||
| 192 | error_reporting($reportingLevel); |
||
| 193 | |||
| 194 | $io->success($this->translator->__('UPGRADE COMPLETE!')); |
||
| 195 | |||
| 196 | return 0; |
||
| 197 | } |
||
| 223 |