| Conditions | 9 |
| Paths | 7 |
| Total Lines | 62 |
| Code Lines | 32 |
| 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 |
||
| 37 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 38 | { |
||
| 39 | parent::execute($input, $output); |
||
| 40 | |||
| 41 | $configFilePath = PathUtils::getAbsolutePath($input->getArgument('target')); |
||
| 42 | $configFileDir = dirname($configFilePath); |
||
| 43 | |||
| 44 | if (!is_writable($configFileDir)) |
||
| 45 | { |
||
| 46 | $output->writeln("<error>Cannot write to {$configFileDir}</error>"); |
||
| 47 | |||
| 48 | return 1; |
||
| 49 | } |
||
| 50 | |||
| 51 | |||
| 52 | $configuration = new Configuration($input->getOption('path') ?: $this->outputStyle->ask('Local path', '.')); |
||
| 53 | $configuration->setIdentity($input->getOption('identity') ?: $this->outputStyle->ask('Identity', get_current_user())); |
||
| 54 | $configuration->setExclude($input->getOption('exclude') ?: $this->outputStyle->askMultiple('Excluded path(s)')); |
||
| 55 | |||
| 56 | // at least one storage driver has to be set up |
||
| 57 | do |
||
| 58 | { |
||
| 59 | $vaultConfig = new VaultConfiguration($this->outputStyle->choice('Storage driver', StorageDriverFactory::getProvidedServiceNames())); |
||
| 60 | $vaultConfig->setTitle($this->outputStyle->ask('Title', $vaultConfig->getAdapter())); |
||
| 61 | $vaultConfig->setLockAdapter($this->outputStyle->choice('Lock adapter', LockAdapterFactory::getProvidedServiceNames(), $vaultConfig->getLockAdapter())); |
||
| 62 | $vaultConfig->setIndexMerger($this->outputStyle->choice('Index merger', IndexMergerFactory::getProvidedServiceNames(), $vaultConfig->getIndexMerger())); |
||
| 63 | $vaultConfig->setConflictHandler($this->outputStyle->choice('Conflict handler', ConflictHandlerFactory::getProvidedServiceNames(), $vaultConfig->getConflictHandler())); |
||
| 64 | $vaultConfig->setOperationListBuilder($this->outputStyle->choice('Operation list builder', OperationListBuilderFactory::getProvidedServiceNames(), $vaultConfig->getOperationListBuilder())); |
||
| 65 | |||
| 66 | while ($settingName = $this->outputStyle->ask('Additional setting name')) |
||
| 67 | { |
||
| 68 | if ($settingValue = $this->outputStyle->ask('Additional setting value')) |
||
| 69 | { |
||
| 70 | $vaultConfig->setSetting($settingName, $settingValue); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | $configuration->addVault($vaultConfig); |
||
| 75 | } |
||
| 76 | while($this->outputStyle->choice('Add another vault?', ['y', 'n'], 'n') === 'y'); |
||
| 77 | |||
| 78 | |||
| 79 | $skipDefaults = !$input->getOption('writeDefaults'); |
||
| 80 | |||
| 81 | $configurationFileWriter = new ConfigurationFileWriter(); |
||
| 82 | |||
| 83 | $output->writeln("The following content will be written to {$configFilePath}:"); |
||
| 84 | $output->writeln($configurationFileWriter->buildConfigurationFile($configuration, $skipDefaults)); |
||
| 85 | |||
| 86 | if ($this->outputStyle->confirm('Continue? ', true)) |
||
| 87 | { |
||
| 88 | $configurationFileWriter->writeConfigurationFile($configuration, $configFilePath, $skipDefaults); |
||
| 89 | |||
| 90 | $output->writeln("<info>Successfully written config file to {$configFilePath}</info>"); |
||
| 91 | } |
||
| 92 | else |
||
| 93 | { |
||
| 94 | $output->writeln("<comment>Aborted</comment>"); |
||
| 95 | } |
||
| 96 | |||
| 97 | return 0; |
||
| 98 | } |
||
| 99 | } |
||
| 100 |