| Conditions | 14 |
| Paths | 58 |
| Total Lines | 50 |
| Code Lines | 33 |
| 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 |
||
| 88 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 89 | { |
||
| 90 | $this->mysqldump = $input->getArgument(self::ARGUMENT_MYSQL_DUMP_FILE); |
||
| 91 | |||
| 92 | $this->schemaPath = $input->getOption(self::OPTION_SCHEMA_PATH); |
||
| 93 | $this->databaseName = $input->getOption(self::OPTION_DATABASE); |
||
| 94 | |||
| 95 | if ($input->getOption(self::OPTION_WRITE)) { |
||
| 96 | $this->write = true; |
||
| 97 | } |
||
| 98 | |||
| 99 | $stream = TokenStream::newFromFile($this->mysqldump); |
||
| 100 | |||
| 101 | $dump = new MysqlDump(); |
||
| 102 | try { |
||
| 103 | $dump->parse($stream); |
||
| 104 | } catch (RuntimeException $e) { |
||
| 105 | throw new RuntimeException($stream->contextualise($e->getMessage())); |
||
| 106 | } catch (Exception $e) { |
||
| 107 | throw new Exception($e->getMessage() . "\n\n" . $e->getTraceAsString()); |
||
| 108 | } |
||
| 109 | |||
| 110 | if ($this->write) { |
||
| 111 | foreach ($dump->databases as $database) { |
||
| 112 | $databaseName = ($database->name == '') ? $this->databaseName : $database->name; |
||
| 113 | if ($databaseName == '') { |
||
| 114 | throw new RuntimeException("No database name specified in dump - please use --database=NAME to supply one"); |
||
| 115 | } |
||
| 116 | $output = "{$this->schemaPath}/$databaseName"; |
||
| 117 | |||
| 118 | if (!is_dir($output)) { |
||
| 119 | if (!@mkdir($output, 0755, true)) { |
||
| 120 | throw new RuntimeException("Could not make directory $output"); |
||
| 121 | } |
||
| 122 | } |
||
| 123 | foreach ($database->tables as $table) { |
||
| 124 | $path = "$output/{$table->name}.sql"; |
||
| 125 | $text = ''; |
||
| 126 | foreach ($table->getDDL() as $query) { |
||
| 127 | $text .= "$query;\n\n"; |
||
| 128 | } |
||
| 129 | if (false === @file_put_contents($path, $text)) { |
||
| 130 | throw new RuntimeException("Could not write $path"); |
||
| 131 | } |
||
| 132 | fprintf(STDERR, "wrote $path\n"); |
||
| 133 | } |
||
| 134 | } |
||
| 135 | } else { |
||
| 136 | foreach ($dump->getDDL() as $query) { |
||
| 137 | echo "$query;\n\n"; |
||
| 138 | } |
||
| 142 |