| Conditions | 6 |
| Paths | 8 |
| Total Lines | 78 |
| 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 declare(strict_types=1); |
||
| 160 | private function init(InputInterface $input, OutputInterface $output): void { |
||
| 161 | $output->writeln( |
||
| 162 | 'Federated Circles is a new feature that allows you to open your circles to other instances of Nextcloud' |
||
| 163 | ); |
||
| 164 | $output->writeln('This feature is a Work in Progress and still in development state.'); |
||
| 165 | $output->writeln(''); |
||
| 166 | |||
| 167 | $helper = $this->getHelper('question'); |
||
| 168 | $question = new ConfirmationQuestion( |
||
| 169 | '<info>Do you want to enable this feature ?</info> (y/N) ', false, '/^(y|Y)/i' |
||
| 170 | ); |
||
| 171 | |||
| 172 | if (!$helper->ask($input, $output, $question)) { |
||
| 173 | $output->writeln('Federated Circles NOT enabled'); |
||
| 174 | |||
| 175 | return; |
||
| 176 | } |
||
| 177 | |||
| 178 | |||
| 179 | $output->writeln(''); |
||
| 180 | $output->writeln( |
||
| 181 | 'Please understand that the feature is <comment>in ALPHA version</comment>, is <comment>not enabled by default</comment>, and <comment>should not be enable</comment> unless you really need it' |
||
| 182 | ); |
||
| 183 | $helper = $this->getHelper('question'); |
||
| 184 | $question = new ConfirmationQuestion( |
||
| 185 | '<info>I understand this but I really want this feature!</info> (y/N) ', false, '/^(y|Y)/i' |
||
| 186 | ); |
||
| 187 | |||
| 188 | if (!$helper->ask($input, $output, $question)) { |
||
| 189 | $output->writeln('Federated Circles NOT enabled'); |
||
| 190 | |||
| 191 | return; |
||
| 192 | } |
||
| 193 | |||
| 194 | |||
| 195 | $currInstance = $this->configService->getLocalInstance(); |
||
| 196 | $output->writeln(''); |
||
| 197 | $output->writeln('The domain name of your instance is: <info>' . $currInstance . '</info>'); |
||
| 198 | $helper = $this->getHelper('question'); |
||
| 199 | $question = |
||
| 200 | new Question('<info>Change your domain name:</info> (' . $currInstance . ') ', $currInstance); |
||
| 201 | |||
| 202 | $newInstance = $helper->ask($input, $output, $question); |
||
| 203 | |||
| 204 | if ($newInstance !== $currInstance) { |
||
| 205 | $this->configService->setAppValue(ConfigService::LOCAL_CLOUD_ID, $newInstance); |
||
| 206 | } |
||
| 207 | |||
| 208 | |||
| 209 | $output->writeln(''); |
||
| 210 | $currScheme = $this->configService->getAppValue(ConfigService::LOCAL_CLOUD_SCHEME); |
||
| 211 | $output->writeln('Current protocol is <info>' . strtoupper($currScheme) . '</info>'); |
||
| 212 | $question = |
||
| 213 | new Question('<info>Change the used protocol:</info> (' . $currScheme . ') ', $currScheme); |
||
| 214 | $newScheme = strtolower($helper->ask($input, $output, $question)); |
||
| 215 | |||
| 216 | if ($newScheme !== $currScheme) { |
||
| 217 | if (!in_array($newScheme, ['http', 'https'])) { |
||
| 218 | $output->writeln('<error>protocol can only be \'https\' or \'http\'</error>'); |
||
| 219 | |||
| 220 | return; |
||
| 221 | } |
||
| 222 | |||
| 223 | $this->configService->setAppValue(ConfigService::LOCAL_CLOUD_SCHEME, $newScheme); |
||
| 224 | } |
||
| 225 | |||
| 226 | $output->writeln(''); |
||
| 227 | $output->writeln(''); |
||
| 228 | $output->writeln('Federated Circles is now <info>enable</info>.'); |
||
| 229 | $output->writeln('Your identity: '); |
||
| 230 | |||
| 231 | $app = $this->remoteService->getAppSignatory(true); |
||
| 232 | |||
| 233 | $output->writeln( |
||
| 234 | '<info>' . json_encode($app, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . '</info>' |
||
| 235 | ); |
||
| 236 | $output->writeln(''); |
||
| 237 | } |
||
| 238 | |||
| 241 |