| Conditions | 5 |
| Paths | 8 |
| Total Lines | 64 |
| Code Lines | 34 |
| 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 |
||
| 58 | public function entitiesAction() |
||
| 59 | { |
||
| 60 | $creationCount = 0; |
||
| 61 | $entitiesRoot = $this->config->get('projectRoot') . '/src/Entity'; |
||
| 62 | |||
| 63 | if (!is_dir($entitiesRoot)) { |
||
| 64 | mkdir($entitiesRoot); |
||
| 65 | } |
||
| 66 | |||
| 67 | $result = DbTables::getTableData($this->config); |
||
| 68 | |||
| 69 | foreach ($result as $table => $fields) { |
||
| 70 | |||
| 71 | $properties = []; |
||
| 72 | $namespace = $this->config->get('namespacePrefix') . '\\Entity'; |
||
| 73 | $className = ucfirst($table) . 'Entity'; |
||
| 74 | |||
| 75 | Output::writeLine('Process table "' . $table . '"', 'warning'); |
||
| 76 | |||
| 77 | $targetFile = $entitiesRoot . '/' . $className . '.php'; |
||
| 78 | |||
| 79 | if (file_exists($targetFile)) { |
||
| 80 | Output::writeLine('Entity "' . $className . '" already exists... skipping.', 'error'); |
||
| 81 | continue; |
||
| 82 | } |
||
| 83 | |||
| 84 | $properties[] = '/**'; |
||
| 85 | |||
| 86 | foreach ($fields as $field) { |
||
| 87 | |||
| 88 | $properties[] = ' * @property ' . $field['Type'] . ' $' . $field['Field']; |
||
| 89 | Output::writeLine('Create property ' . $field['Field']); |
||
| 90 | |||
| 91 | } |
||
| 92 | |||
| 93 | $properties[] = ' */'; |
||
| 94 | |||
| 95 | $props = implode(PHP_EOL, $properties); |
||
| 96 | $props = preg_replace( |
||
| 97 | array_keys($this->mysqlTypeMapping), |
||
| 98 | array_values($this->mysqlTypeMapping), |
||
| 99 | $props |
||
| 100 | ); |
||
| 101 | |||
| 102 | $fixture = str_replace( |
||
| 103 | ['{$namespace}', '{$props}', '{$table}', '{$className}'], |
||
| 104 | [$namespace, $props, $table, $className], |
||
| 105 | file_get_contents(__DIR__ . '/../Fixture/Entity.fixture') |
||
| 106 | ); |
||
| 107 | |||
| 108 | |||
| 109 | file_put_contents($entitiesRoot . '/' . $className . '.php', $fixture); |
||
| 110 | |||
| 111 | Output::writeLine('Entity for table "' . $table . '" successfully generated', 'success'); |
||
| 112 | |||
| 113 | $creationCount++; |
||
| 114 | |||
| 115 | Output::writeEmptyLine(); |
||
| 116 | |||
| 117 | } |
||
| 118 | |||
| 119 | Output::writeLine($creationCount . ' entities generated', 'success'); |
||
| 120 | |||
| 121 | } |
||
| 122 | |||
| 123 | } |