| Conditions | 5 |
| Paths | 6 |
| Total Lines | 59 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | 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 |
||
| 119 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 120 | { |
||
| 121 | if (version_compare($this->installed, UpgraderController::ZIKULACORE_MINIMUM_UPGRADE_VERSION, '<')) { |
||
| 122 | $output->writeln($this->translator->trans('The currently installed version of Zikula (%currentVersion%) is too old. You must upgrade to version %minimumVersion% before you can use this upgrade.', ['%currentVersion%' => $this->installed, '%minimumVersion%' => UpgraderController::ZIKULACORE_MINIMUM_UPGRADE_VERSION])); |
||
| 123 | |||
| 124 | return 1; |
||
| 125 | } |
||
| 126 | |||
| 127 | $io = new SymfonyStyle($input, $output); |
||
| 128 | $io->title($this->translator->trans('Zikula Upgrader Script')); |
||
| 129 | $io->section($this->translator->trans('*** UPGRADING TO ZIKULA CORE %version% ***', ['%version%' => ZikulaKernel::VERSION])); |
||
| 130 | $io->text($this->translator->trans('Upgrading Zikula in %env% environment.', ['%env%' => $this->kernel->getEnvironment()])); |
||
| 131 | |||
| 132 | $warnings = $this->controllerHelper->initPhp(); |
||
| 133 | if (!empty($warnings)) { |
||
| 134 | $this->printWarnings($output, $warnings); |
||
| 135 | |||
| 136 | return 2; |
||
| 137 | } |
||
| 138 | |||
| 139 | $yamlManager = new YamlDumper($this->kernel->getProjectDir() . '/config', 'services_custom.yaml'); |
||
| 140 | // tell the core that we are upgrading |
||
| 141 | $yamlManager->setParameter('upgrading', true); |
||
| 142 | |||
| 143 | $this->migrateUsers($io, $output); |
||
| 144 | |||
| 145 | // get the settings from user input |
||
| 146 | $settings = $this->getHelper('form')->interactUsingForm(LocaleType::class, $input, $output, [ |
||
| 147 | 'choices' => $this->localeApi->getSupportedLocaleNames(), |
||
| 148 | 'choice_loader' => null |
||
| 149 | ]); |
||
| 150 | |||
| 151 | $data = $this->getHelper('form')->interactUsingForm(LoginType::class, $input, $output); |
||
| 152 | foreach ($data as $k => $v) { |
||
| 153 | $data[$k] = base64_encode($v); // encode so values are 'safe' for json |
||
| 154 | } |
||
| 155 | $settings = array_merge($settings, $data); |
||
| 156 | |||
| 157 | $data = $this->getHelper('form')->interactUsingForm(RequestContextType::class, $input, $output); |
||
| 158 | foreach ($data as $k => $v) { |
||
| 159 | $newKey = str_replace(':', '.', $k); |
||
| 160 | $data[$newKey] = $v; |
||
| 161 | unset($data[$k]); |
||
| 162 | } |
||
| 163 | $settings = array_merge($settings, $data); |
||
| 164 | |||
| 165 | $this->printSettings($settings, $io); |
||
| 166 | $io->newLine(); |
||
| 167 | |||
| 168 | // write the parameters into config/services_custom.yaml |
||
| 169 | $params = array_merge($yamlManager->getParameters(), $settings); |
||
| 170 | $yamlManager->setParameters($params); |
||
| 171 | |||
| 172 | // upgrade! |
||
| 173 | $this->stageHelper->handleAjaxStage($this->ajaxUpgraderStage, $io); |
||
| 174 | |||
| 175 | $io->success($this->translator->trans('UPGRADE COMPLETE!')); |
||
| 176 | |||
| 177 | return 0; |
||
| 178 | } |
||
| 204 |