Conditions | 11 |
Paths | 147 |
Total Lines | 83 |
Code Lines | 51 |
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 |
||
90 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
91 | { |
||
92 | $io = new SymfonyStyle($input, $output); |
||
93 | $io->title($this->translator->trans('Zikula Installer Script')); |
||
94 | |||
95 | if (true === $this->installed) { |
||
96 | $io->error($this->translator->trans('Zikula already appears to be installed.')); |
||
97 | |||
98 | return 1; |
||
99 | } |
||
100 | |||
101 | $warnings = $this->controllerHelper->initPhp(); |
||
102 | if (!empty($warnings)) { |
||
103 | $this->printWarnings($output, $warnings); |
||
104 | |||
105 | return 2; |
||
106 | } |
||
107 | $checks = $this->controllerHelper->requirementsMet(); |
||
108 | if (true !== $checks) { |
||
|
|||
109 | $this->printRequirementsWarnings($output, $checks); |
||
110 | |||
111 | return 2; |
||
112 | } |
||
113 | |||
114 | if ($input->isInteractive()) { |
||
115 | $io->comment($this->translator->trans('Configuring Zikula installation in %env% environment.', ['%env%' => $this->kernel->getEnvironment()])); |
||
116 | $io->comment($this->translator->trans('Please follow the instructions to install Zikula %version%.', ['%version%' => ZikulaKernel::VERSION])); |
||
117 | } |
||
118 | |||
119 | // get the settings from user input |
||
120 | $settings = $this->getHelper('form')->interactUsingForm(LocaleType::class, $input, $output, [ |
||
121 | 'choices' => $this->localeApi->getSupportedLocaleNames(), |
||
122 | 'choice_loader' => null |
||
123 | ]); |
||
124 | $data = $this->getHelper('form')->interactUsingForm(RequestContextType::class, $input, $output); |
||
125 | foreach ($data as $k => $v) { |
||
126 | $newKey = str_replace(':', '.', $k); |
||
127 | $data[$newKey] = $v; |
||
128 | unset($data[$k]); |
||
129 | } |
||
130 | $settings = array_merge($settings, $data); |
||
131 | $data = $this->getHelper('form')->interactUsingForm(DbCredsType::class, $input, $output); |
||
132 | |||
133 | $dbCredsHelper = new DbCredsHelper(); |
||
134 | $databaseUrl = $dbCredsHelper->buildDatabaseUrl($data); |
||
135 | try { |
||
136 | $vars = ['DATABASE_URL' => '!\'' . $databaseUrl . '\'']; |
||
137 | $helper = new LocalDotEnvHelper($this->kernel->getProjectDir()); |
||
138 | $helper->writeLocalEnvVars($vars); |
||
139 | } catch (IOExceptionInterface $exception) { |
||
140 | $io->error(sprintf('Cannot write to %s file.', $this->kernel->getProjectDir() . '/.env.local') . ' ' . $exception->getMessage()); |
||
141 | } |
||
142 | |||
143 | $data = $this->getHelper('form')->interactUsingForm(CreateAdminType::class, $input, $output); |
||
144 | foreach ($data as $k => $v) { |
||
145 | $data[$k] = base64_encode($v); // encode so values are 'safe' for json |
||
146 | } |
||
147 | $settings = array_merge($settings, $data); |
||
148 | |||
149 | if ($input->isInteractive()) { |
||
150 | $io->success($this->translator->trans('Configuration successful. Please verify your parameters below:')); |
||
151 | $io->comment($this->translator->trans('(Admin credentials have been encoded to make them json-safe.)')); |
||
152 | } |
||
153 | |||
154 | $this->printSettings($settings, $io); |
||
155 | $io->newLine(); |
||
156 | |||
157 | if ($input->isInteractive()) { |
||
158 | $confirmation = $io->confirm($this->translator->trans('Start installation?'), true); |
||
159 | |||
160 | if (!$confirmation) { |
||
161 | $io->error($this->translator->trans('Installation aborted')); |
||
162 | |||
163 | return 3; |
||
164 | } |
||
165 | } |
||
166 | |||
167 | // write parameters into config/services_custom.yaml and env vars into .env.local |
||
168 | $this->parameterHelper->initializeParameters($settings); |
||
169 | |||
170 | $io->success($this->translator->trans('First stage of installation complete. Run `php bin/console zikula:install:finish` to complete the installation.')); |
||
171 | |||
172 | return 0; |
||
173 | } |
||
175 |