| Conditions | 7 |
| Paths | 21 |
| Total Lines | 54 |
| Code Lines | 34 |
| 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 |
||
| 98 | private function updateWhatRecord(InputInterface $input, OutputInterface $output): void |
||
| 99 | { |
||
| 100 | $config = $input->getArgument('config'); |
||
| 101 | |||
| 102 | try { |
||
| 103 | $fieldConfig = FieldConfig::fromArray( |
||
| 104 | Yaml::parse( |
||
| 105 | file_get_contents($config) |
||
| 106 | ) |
||
| 107 | ); |
||
| 108 | } catch (\Exception $exception) { |
||
| 109 | $output->writeln("<error>Invalid configuration file. {$exception->getMessage()}</error>"); |
||
| 110 | return; |
||
| 111 | } |
||
| 112 | |||
| 113 | try { |
||
| 114 | $field = $this->fieldManager->readByHandle($fieldConfig->getHandle()); |
||
| 115 | |||
| 116 | if (!$input->getOption('yes-mode')) { |
||
| 117 | $sure = new ConfirmationQuestion( |
||
| 118 | '<comment>Do you want to update the field with id: ' . $field->getId() . '?</comment> (y/n) ', |
||
| 119 | false |
||
| 120 | ); |
||
| 121 | |||
| 122 | if (!$this->getHelper('question')->ask($input, $output, $sure)) { |
||
| 123 | $output->writeln('<comment>Cancelled, nothing updated.</comment>', false); |
||
| 124 | return; |
||
| 125 | } |
||
| 126 | } |
||
| 127 | } catch (FieldNotFoundException $exception) { |
||
| 128 | $output->writeln( |
||
| 129 | 'You are trying to update a field with handle: ' . $fieldConfig->getHandle() . '. No field with ' . |
||
| 130 | 'that handle exists in the database, use sf:create-field if you actually need a new field, or ' . |
||
| 131 | 'select an existing field id that will be overwritten with this config.' |
||
| 132 | ); |
||
| 133 | |||
| 134 | $sure = new ConfirmationQuestion( |
||
| 135 | '<comment>Do you want to continue to select a field that will be overwritten?</comment> (y/n) ', |
||
| 136 | false |
||
| 137 | ); |
||
| 138 | |||
| 139 | if (!$this->getHelper('question')->ask($input, $output, $sure)) { |
||
| 140 | $output->writeln('<comment>Cancelled, nothing updated.</comment>'); |
||
| 141 | return; |
||
| 142 | } |
||
| 143 | |||
| 144 | $field = $this->getField($input, $output); |
||
| 145 | } |
||
| 146 | |||
| 147 | $this->fieldManager->updateByConfig($fieldConfig, $field); |
||
| 148 | if (!$input->getOption('yes-mode')) { |
||
| 149 | $this->renderTable($output, $this->fieldManager->readAll(), 'Field updated!'); |
||
| 150 | } else { |
||
| 151 | $output->writeln('Field updated!'); |
||
| 152 | } |
||
| 155 |