| Conditions | 10 |
| Paths | 22 |
| Total Lines | 53 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | 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 |
||
| 113 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 114 | { |
||
| 115 | $this->detectDbSettings($output); |
||
| 116 | $this->writeSection($output, 'Import MySQL Database'); |
||
| 117 | $dbHelper = $this->getHelper('database'); |
||
| 118 | |||
| 119 | $fileName = $this->checkFilename($input); |
||
| 120 | |||
| 121 | $compressor = $this->getCompressor($input->getOption('compression')); |
||
| 122 | |||
| 123 | if ($input->getOption('optimize')) { |
||
| 124 | if ($input->getOption('only-command')) { |
||
| 125 | throw new InvalidArgumentException('Options --only-command and --optimize are not compatible'); |
||
| 126 | } |
||
| 127 | if ($input->getOption('compression')) { |
||
| 128 | throw new InvalidArgumentException('Options --compression and --optimize are not compatible'); |
||
| 129 | } |
||
| 130 | $output->writeln('<comment>Optimizing <info>' . $fileName . '</info> to temporary file'); |
||
| 131 | $fileName = $this->optimize($fileName); |
||
| 132 | } |
||
| 133 | |||
| 134 | // create import command |
||
| 135 | $exec = $compressor->getDecompressingCommand( |
||
| 136 | 'mysql ' . $dbHelper->getMysqlClientToolConnectionString(), |
||
| 137 | $fileName |
||
| 138 | ); |
||
| 139 | if ($input->getOption('only-command')) { |
||
| 140 | $output->writeln($exec); |
||
| 141 | return; |
||
| 142 | } else { |
||
| 143 | if ($input->getOption('only-if-empty') |
||
| 144 | && count($dbHelper->getTables()) > 0 |
||
| 145 | ) { |
||
| 146 | $output->writeln('<comment>Skip import. Database is not empty</comment>'); |
||
| 147 | |||
| 148 | return; |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 152 | if ($input->getOption('drop')) { |
||
| 153 | $dbHelper->dropDatabase($output); |
||
| 154 | $dbHelper->createDatabase($output); |
||
| 155 | } |
||
| 156 | if ($input->getOption('drop-tables')) { |
||
| 157 | $dbHelper->dropTables($output); |
||
| 158 | } |
||
| 159 | |||
| 160 | $this->doImport($output, $fileName, $exec); |
||
| 161 | |||
| 162 | if ($input->getOption('optimize')) { |
||
| 163 | unlink($fileName); |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 211 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.