| Conditions | 7 |
| Paths | 7 |
| Total Lines | 57 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 72 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 73 | { |
||
| 74 | $io = new SymfonyStyle($input, $output); |
||
| 75 | |||
| 76 | try { |
||
| 77 | $key = $this->validateKey($input->getArgument('key')); |
||
| 78 | } catch (\Exception $e) { |
||
| 79 | $io->error($e->getMessage()); |
||
| 80 | |||
| 81 | return 1; |
||
| 82 | } |
||
| 83 | |||
| 84 | try { |
||
| 85 | $value = $this->validateValue($input->getArgument('value')); |
||
| 86 | } catch (\Exception $e) { |
||
| 87 | $io->error($e->getMessage()); |
||
| 88 | |||
| 89 | return 1; |
||
| 90 | } |
||
| 91 | |||
| 92 | try { |
||
| 93 | if ( |
||
| 94 | $this->storage->has($key) && false === $io->confirm( |
||
| 95 | sprintf('Key "%s" already exists. Overwrite?', $key) |
||
| 96 | ) |
||
| 97 | ) { |
||
| 98 | $io->success('Your secrets file was left intact.'); |
||
| 99 | |||
| 100 | return 0; |
||
| 101 | } |
||
| 102 | } catch (\Exception $e) { |
||
| 103 | $io->error($e->getMessage()); |
||
| 104 | |||
| 105 | return 1; |
||
| 106 | } |
||
| 107 | |||
| 108 | try { |
||
| 109 | $this->storage->store($key, $value, !$input->getOption('no-encrypt')); |
||
| 110 | } catch (\Exception $e) { |
||
| 111 | $io->error($e->getMessage()); |
||
| 112 | |||
| 113 | return 1; |
||
| 114 | } |
||
| 115 | |||
| 116 | $io->success('Your secrets file has been successfully updated!'); |
||
| 117 | $io->comment('Tip: you can use your new secret as a parameter:'); |
||
| 118 | |||
| 119 | $io->writeln( |
||
| 120 | <<<EOF |
||
| 121 | # config/services.yaml |
||
| 122 | parameters: |
||
| 123 | {$key}: '%env(shh:key:{$key}:json:file:SHH_SECRETS_FILE)%' |
||
| 124 | |||
| 125 | EOF |
||
| 126 | ); |
||
| 127 | |||
| 128 | return 0; |
||
| 129 | } |
||
| 161 |