| Conditions | 11 |
| Paths | 63 |
| Total Lines | 66 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 115 | private function updateWhatRecord(InputInterface $input, OutputInterface $output): void |
||
| 116 | { |
||
| 117 | if (is_null($sectionConfig = $this->getConfig($input, $output))) { |
||
| 118 | return; |
||
| 119 | } |
||
| 120 | |||
| 121 | try { |
||
| 122 | $section = $this->sectionManager->readByHandle($sectionConfig->getHandle()); |
||
| 123 | if (!$input->getOption('yes-mode')) { |
||
| 124 | $sure = new ConfirmationQuestion( |
||
| 125 | '<comment>Do you want to update the section with id: ' . $section->getId() . '?</comment> (y/n) ', |
||
| 126 | false |
||
| 127 | ); |
||
| 128 | |||
| 129 | if (!$this->questionHelper->ask($input, $output, $sure)) { |
||
| 130 | $output->writeln('<comment>Cancelled, nothing updated.</comment>', false); |
||
|
|
|||
| 131 | return; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | } catch (SectionNotFoundException $exception) { |
||
| 135 | $output->writeln( |
||
| 136 | 'You are trying to update a section with handle: ' . $sectionConfig->getHandle() . '. No field with ' . |
||
| 137 | 'that handle exists in the database, use sf:create-section is you actually need a new section, or' . |
||
| 138 | 'select an existing section id that will be overwritten with this config.' |
||
| 139 | ); |
||
| 140 | |||
| 141 | $sure = new ConfirmationQuestion( |
||
| 142 | '<comment>Do you want to continue to select a section that will be overwritten?</comment> (y/n) ', |
||
| 143 | false |
||
| 144 | ); |
||
| 145 | |||
| 146 | if (!$this->getHelper('question')->ask($input, $output, $sure)) { |
||
| 147 | $output->writeln('<comment>Cancelled, nothing updated</comment>'); |
||
| 148 | return; |
||
| 149 | } |
||
| 150 | |||
| 151 | $section = $this->getSection($input, $output); |
||
| 152 | } |
||
| 153 | |||
| 154 | $inHistory = $input->getOption('in-history'); |
||
| 155 | $notInHistory = $input->getOption('not-in-history'); |
||
| 156 | |||
| 157 | if (!$inHistory && !$notInHistory) { |
||
| 158 | $inHistory = false; |
||
| 159 | // @todo: Make it a section config (if it can be manually told to go to history) |
||
| 160 | // $inHistory = $this->getHelper('question')->ask( |
||
| 161 | // $input, |
||
| 162 | // $output, |
||
| 163 | // new ConfirmationQuestion( |
||
| 164 | // '<comment>Do you want to store the current version in history?</comment> (y/n) ', |
||
| 165 | // false |
||
| 166 | // ) |
||
| 167 | // ); |
||
| 168 | } |
||
| 169 | |||
| 170 | if ($notInHistory) { |
||
| 171 | $inHistory = false; |
||
| 172 | } |
||
| 173 | |||
| 174 | $this->sectionManager->updateByConfig($sectionConfig, $section, $inHistory); |
||
| 175 | if (!$input->getOption('yes-mode')) { |
||
| 176 | $this->renderTable($output, $this->sectionManager->readAll(), 'Section updated!'); |
||
| 177 | } else { |
||
| 178 | $output->writeln( |
||
| 179 | 'Section updated! ' . |
||
| 180 | ($inHistory ? 'Old version stored in history.' : 'Nothing stored in history.') |
||
| 181 | ); |
||
| 185 |