Conditions | 12 |
Paths | 43 |
Total Lines | 58 |
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 |
||
116 | protected function execute(InputInterface $input, OutputInterface $output) |
||
117 | { |
||
118 | $this->detectDbSettings($output); |
||
119 | |||
120 | $this->writeSection($output, 'Import MySQL Database'); |
||
121 | $dbHelper = $this->getHelper('database'); |
||
122 | |||
123 | $fileName = $this->checkFilename($input); |
||
124 | |||
125 | $compressor = $this->getCompressor($input->getOption('compression')); |
||
126 | |||
127 | if ($input->getOption('optimize')) { |
||
128 | if ($fileName === '-') { |
||
129 | throw new InvalidArgumentException('Option --optimize not compatible with STDIN import'); |
||
130 | } |
||
131 | if ($input->getOption('only-command')) { |
||
132 | throw new InvalidArgumentException('Options --only-command and --optimize are not compatible'); |
||
133 | } |
||
134 | if ($input->getOption('compression')) { |
||
135 | throw new InvalidArgumentException('Options --compression and --optimize are not compatible'); |
||
136 | } |
||
137 | $output->writeln('<comment>Optimizing <info>' . $fileName . '</info> to temporary file'); |
||
138 | $fileName = $this->optimize($fileName); |
||
139 | } |
||
140 | |||
141 | // create import command |
||
142 | $exec = 'mysql ' . $dbHelper->getMysqlClientToolConnectionString(); |
||
143 | if ($fileName !== '-') { |
||
144 | $exec = $compressor->getDecompressingCommand($exec, $fileName); |
||
145 | } |
||
146 | |||
147 | if ($input->getOption('only-command')) { |
||
148 | $output->writeln($exec); |
||
149 | return; |
||
150 | } else { |
||
151 | if ($input->getOption('only-if-empty') |
||
152 | && count($dbHelper->getTables()) > 0 |
||
153 | ) { |
||
154 | $output->writeln('<comment>Skip import. Database is not empty</comment>'); |
||
155 | |||
156 | return; |
||
157 | } |
||
158 | } |
||
159 | |||
160 | if ($input->getOption('drop')) { |
||
161 | $dbHelper->dropDatabase($output); |
||
162 | $dbHelper->createDatabase($output); |
||
163 | } |
||
164 | if ($input->getOption('drop-tables')) { |
||
165 | $dbHelper->dropTables($output); |
||
166 | } |
||
167 | |||
168 | $this->doImport($output, $fileName, $exec); |
||
169 | |||
170 | if ($input->getOption('optimize')) { |
||
171 | unlink($fileName); |
||
172 | } |
||
173 | } |
||
174 | |||
223 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.