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