| Conditions | 11 |
| Paths | 8 |
| Total Lines | 73 |
| 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 |
||
| 31 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 32 | { |
||
| 33 | $this->setUpIO($input, $output); |
||
| 34 | |||
| 35 | if ($this->getConfiguration($this->getContainer($output), $input)) |
||
| 36 | { |
||
| 37 | $output->writeln("This directory is already configured as an archive."); |
||
| 38 | |||
| 39 | return 1; |
||
| 40 | } |
||
| 41 | |||
| 42 | $configFilePath = PathUtils::getAbsolutePath($input->getOption('config')); |
||
| 43 | $configFileDir = dirname($configFilePath); |
||
| 44 | |||
| 45 | if (!is_writable($configFileDir)) |
||
| 46 | { |
||
| 47 | $output->writeln("<error>Cannot write to {$configFileDir}</error>"); |
||
| 48 | |||
| 49 | return 1; |
||
| 50 | } |
||
| 51 | |||
| 52 | |||
| 53 | $container = $this->getContainer($output); |
||
| 54 | |||
| 55 | $configuration = new Configuration(); |
||
| 56 | $configuration->setPath($input->getOption('path') ?: $this->consoleStyle->ask('Local path', '.')); |
||
| 57 | $configuration->setIdentity($input->getOption('identity') ?: $this->consoleStyle->ask('Identity', sprintf('%s@%s', get_current_user(), gethostname()))); |
||
| 58 | $configuration->setExclude($input->getOption('exclude') ?: $this->consoleStyle->askMultiple('Excluded path(s)')); |
||
| 59 | $configuration->setIndexBuilder($input->getOption('indexBuilder') ?: $this->consoleStyle->choice('Index builder', $container->getIndexBuilderNames(), $configuration->getIndexBuilder())); |
||
| 60 | |||
| 61 | // at least one storage driver has to be set up |
||
| 62 | do |
||
| 63 | { |
||
| 64 | $vaultConfig = new VaultConfiguration($configuration); |
||
| 65 | $vaultConfig->setAdapter($this->consoleStyle->choice('Storage driver', $container->getStorageAdapterNames())); |
||
| 66 | $vaultConfig->setTitle($this->consoleStyle->ask('Title', $vaultConfig->getAdapter())); |
||
| 67 | $vaultConfig->setVaultLayout($this->consoleStyle->choice('Vault layout', $container->getVaultLayoutNames(), $vaultConfig->getVaultLayout())); |
||
| 68 | $vaultConfig->setLockAdapter($this->consoleStyle->choice('Lock adapter', $container->getLockAdapterNames(), $vaultConfig->getLockAdapter())); |
||
| 69 | $vaultConfig->setIndexMerger($this->consoleStyle->choice('Index merger', $container->getIndexMergerNames(), $vaultConfig->getIndexMerger())); |
||
| 70 | $vaultConfig->setConflictHandler($this->consoleStyle->choice('Conflict handler', $container->getConflictHandlerNames(), $vaultConfig->getConflictHandler())); |
||
| 71 | $vaultConfig->setOperationListBuilder($this->consoleStyle->choice('Operation list builder', $container->getOperationListBuilderNames(), $vaultConfig->getOperationListBuilder())); |
||
| 72 | |||
| 73 | while ($settingName = $this->consoleStyle->ask('Additional setting name')) |
||
| 74 | { |
||
| 75 | if ($settingValue = $this->consoleStyle->ask('Additional setting value')) |
||
| 76 | { |
||
| 77 | $vaultConfig->setSetting($settingName, $settingValue); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | } |
||
| 81 | while($this->consoleStyle->choice('Add another vault?', ['y', 'n'], 'n') === 'y'); |
||
| 82 | |||
| 83 | |||
| 84 | $skipDefaults = !$input->getOption('writeDefaults'); |
||
| 85 | |||
| 86 | $configurationFileWriter = new ConfigurationFileWriter(); |
||
| 87 | |||
| 88 | $output->writeln("The following content will be written to {$configFilePath}:"); |
||
| 89 | $output->writeln($configurationFileWriter->buildConfigurationFile($configuration, $skipDefaults)); |
||
| 90 | |||
| 91 | if ($this->consoleStyle->confirm('Continue? ', true)) |
||
| 92 | { |
||
| 93 | $configurationFileWriter->writeConfigurationFile($configuration, $configFilePath, $skipDefaults); |
||
| 94 | |||
| 95 | $output->writeln("<info>Successfully written config file to {$configFilePath}</info>"); |
||
| 96 | } |
||
| 97 | else |
||
| 98 | { |
||
| 99 | $output->writeln("<comment>Aborted</comment>"); |
||
| 100 | } |
||
| 101 | |||
| 102 | return 0; |
||
| 103 | } |
||
| 104 | } |
||
| 105 |