Conditions | 11 |
Paths | 63 |
Total Lines | 64 |
Code Lines | 40 |
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 |
||
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 | |||
135 | } catch (SectionNotFoundException $exception) { |
||
136 | $output->writeln( |
||
137 | 'You are trying to update a section with handle: ' . $sectionConfig->getHandle() . '. No field with ' . |
||
138 | 'that handle exists in the database, use sf:create-section is you actually need a new section, or' . |
||
139 | 'select an existing section id that will be overwritten with this config.' |
||
140 | ); |
||
141 | |||
142 | $sure = new ConfirmationQuestion( |
||
143 | '<comment>Do you want to continue to select a section that will be overwritten?</comment> (y/n) ', 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 = $this->getHelper('question')->ask( |
||
159 | $input, |
||
160 | $output, |
||
161 | new ConfirmationQuestion( |
||
162 | '<comment>Do you want to store the current version in history?</comment> (y/n) ', |
||
163 | false |
||
164 | ) |
||
165 | ); |
||
166 | } |
||
167 | |||
168 | if ($notInHistory) { |
||
169 | $inHistory = false; |
||
170 | } |
||
171 | |||
172 | $this->sectionManager->updateByConfig($sectionConfig, $section, $inHistory); |
||
173 | if (!$input->getOption('yes-mode')) { |
||
174 | $this->renderTable($output, $this->sectionManager->readAll(), 'Section updated!'); |
||
175 | } else { |
||
176 | $output->writeln( |
||
177 | 'Section updated! ' . |
||
178 | ($inHistory ? 'Old version stored in history.' : 'Nothing stored in history.') |
||
179 | ); |
||
183 |