| Conditions | 9 |
| Paths | 65 |
| Total Lines | 52 |
| Code Lines | 31 |
| 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 describeColumns(AbstractTable $schema) |
||
| 89 | { |
||
| 90 | $columnsTable = $this->table([ |
||
| 91 | 'Column:', |
||
| 92 | 'Database Type:', |
||
| 93 | 'Abstract Type:', |
||
| 94 | 'PHP Type:', |
||
| 95 | 'Default Value:' |
||
| 96 | ]); |
||
| 97 | |||
| 98 | foreach ($schema->getColumns() as $column) { |
||
| 99 | $name = $column->getName(); |
||
| 100 | $type = $column->getType(); |
||
| 101 | |||
| 102 | $abstractType = $column->abstractType(); |
||
| 103 | $defaultValue = $column->getDefaultValue(); |
||
| 104 | |||
| 105 | if ($column->getSize()) { |
||
| 106 | $type .= " ({$column->getSize()})"; |
||
| 107 | } |
||
| 108 | |||
| 109 | if ($column->abstractType() == 'decimal') { |
||
| 110 | $type .= " ({$column->getPrecision()}, {$column->getScale()})"; |
||
| 111 | } |
||
| 112 | |||
| 113 | if (in_array($column->getName(), $schema->getPrimaryKeys())) { |
||
| 114 | $name = "<fg=magenta>{$name}</fg=magenta>"; |
||
| 115 | } |
||
| 116 | |||
| 117 | if (in_array($abstractType, ['primary', 'bigPrimary'])) { |
||
| 118 | $abstractType = "<fg=magenta>{$abstractType}</fg=magenta>"; |
||
| 119 | } |
||
| 120 | |||
| 121 | if ($defaultValue instanceof FragmentInterface) { |
||
| 122 | $defaultValue = "<info>{$defaultValue}</info>"; |
||
| 123 | } |
||
| 124 | |||
| 125 | if ($defaultValue instanceof \DateTimeInterface) { |
||
| 126 | $defaultValue = $defaultValue->format('c'); |
||
| 127 | } |
||
| 128 | |||
| 129 | $columnsTable->addRow([ |
||
| 130 | $name, |
||
| 131 | $type, |
||
| 132 | $abstractType, |
||
| 133 | $column->phpType(), |
||
| 134 | $defaultValue ?: self::SKIP |
||
| 135 | ]); |
||
| 136 | } |
||
| 137 | |||
| 138 | $columnsTable->render(); |
||
| 139 | } |
||
| 140 | |||
| 194 | } |