| Conditions | 12 |
| Paths | 100 |
| Total Lines | 43 |
| 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 |
||
| 43 | public function generate($databaseName): MysqlDatabase |
||
| 44 | { |
||
| 45 | $tables = []; |
||
| 46 | $mysqlDatabase = new MysqlDatabase($databaseName); |
||
| 47 | try { |
||
| 48 | $dataTables = $this->resolve(); |
||
| 49 | } catch (\Exception $e) { |
||
| 50 | throw new JsonInvalidFormatException('An unexpected error are throw when you check json syntax'); |
||
| 51 | } |
||
| 52 | foreach ($dataTables as $tableName => $dataTable) { |
||
| 53 | try { |
||
| 54 | $table = new MysqlDatabaseTable($tableName); |
||
| 55 | } catch (TablenameHasNotDefinedException $e) { |
||
| 56 | throw $e; |
||
| 57 | } |
||
| 58 | if (isset($dataTable['collate'])) { |
||
| 59 | $table->setCollate($dataTable['collate']); |
||
| 60 | } |
||
| 61 | foreach ((array) $dataTable['columns'] as $columnName => $row) { |
||
| 62 | $column = new MysqlDatabaseColumn($columnName, $row['type'], $row['length'], $row['nullable'], $row['defaultValue'], $row['extra']); |
||
| 63 | if (isset($row['collate']) || $table->getCollate()) { |
||
| 64 | $column->setCollate($row['collate']); |
||
| 65 | } |
||
| 66 | $table->addColumn($column); |
||
| 67 | |||
| 68 | } |
||
| 69 | foreach ((array) $dataTable['indexes'] as $row) { |
||
| 70 | $table->addIndex($row['columns'], $row['name']); |
||
| 71 | } |
||
| 72 | if (isset($dataTable['primary'])) { |
||
| 73 | $table->addPrimary((array) $dataTable['primary']); |
||
| 74 | } |
||
| 75 | foreach ((array) $dataTable['uniques'] as $row) { |
||
| 76 | $table->addUnique($row['columns'], $row['name']); |
||
| 77 | } |
||
| 78 | $tables[] = $table; |
||
| 79 | } |
||
| 80 | |||
| 81 | foreach ($tables as $table) { |
||
| 82 | $mysqlDatabase->addTable($table); |
||
| 83 | } |
||
| 84 | |||
| 85 | return $mysqlDatabase; |
||
| 86 | } |
||
| 168 |