| Conditions | 11 |
| Paths | 52 |
| Total Lines | 42 |
| Code Lines | 28 |
| 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 |
||
| 41 | public function generate() |
||
| 42 | { |
||
| 43 | $tables = []; |
||
| 44 | try { |
||
| 45 | $dataTables = $this->resolve(); |
||
| 46 | } catch (\Exception $e) { |
||
| 47 | $this->error('An unexpected error are throw when you check json syntax'); |
||
| 48 | |||
| 49 | return []; |
||
| 50 | } |
||
| 51 | foreach ($dataTables as $tableName => $dataTable) { |
||
| 52 | try { |
||
| 53 | $table = new MysqlDatabaseTable($tableName); |
||
| 54 | } catch (TablenameHasNotDefinedException $e) { |
||
| 55 | throw $e; |
||
| 56 | } catch (\Exception $e) { |
||
| 57 | continue; |
||
| 58 | } |
||
| 59 | if (isset($row['collate'])) { |
||
| 60 | $table->setCollate($dataTable['collate']); |
||
| 61 | } |
||
| 62 | foreach ((array)$dataTable['columns'] as $columnName => $row) { |
||
| 63 | $column = new MysqlDatabaseColumn($columnName, $row['type'], $row['length'], $row['nullable'], $row['defaultValue'], $row['extra']); |
||
| 64 | if (isset($row['collate'])) { |
||
| 65 | $column->setCollate($row['collate']); |
||
| 66 | } |
||
| 67 | $table->addColumn($column); |
||
| 68 | |||
| 69 | } |
||
| 70 | foreach ((array)$dataTable['indexes'] as $row) { |
||
| 71 | $table->addIndex($row['columns'], $row['name']); |
||
| 72 | } |
||
| 73 | if (isset($dataTable['primary'])) { |
||
| 74 | $table->addPrimary((array)$dataTable['primary']); |
||
| 75 | } |
||
| 76 | foreach ((array)$dataTable['uniques'] as $row) { |
||
| 77 | $table->addUnique($row['columns'], $row['name']); |
||
| 78 | } |
||
| 79 | $tables[] = $table; |
||
| 80 | } |
||
| 81 | |||
| 82 | return $tables; |
||
| 83 | } |
||
| 162 |
This check marks files that end in a newline character, i.e. an empy line.