| Conditions | 7 |
| Paths | 9 |
| Total Lines | 52 |
| Code Lines | 30 |
| 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 |
||
| 110 | public function inspect($table_name): TableManipulationInterface |
||
| 111 | { |
||
| 112 | if (isset($this->table_cache[$table_name])) { |
||
| 113 | return $this->table_cache[$table_name]; |
||
| 114 | } |
||
| 115 | |||
| 116 | |||
| 117 | $describe = (new Describe($table_name)); |
||
| 118 | $describe->connection($this->connection()); |
||
| 119 | $description = $describe->ret(); |
||
| 120 | |||
| 121 | // TODO test this when all is back to normal 2021.03.09 |
||
| 122 | if ($description === false) { |
||
| 123 | throw new \PDOException("Unable to describe $table_name"); |
||
| 124 | } |
||
| 125 | |||
| 126 | $table = new Manipulation($table_name, $this->connection()); |
||
| 127 | |||
| 128 | foreach ($description as $column_name => $specs) { |
||
| 129 | $column = new Column($table, $column_name, $specs); |
||
| 130 | |||
| 131 | // handling usage constraints |
||
| 132 | if (isset($this->unique_by_table[$table_name][$column_name])) { |
||
| 133 | $unique_name = $this->unique_by_table[$table_name][$column_name][0]; |
||
| 134 | |||
| 135 | switch (count($this->unique_by_table[$table_name][$column_name])) { |
||
| 136 | case 2: // constraint name + column |
||
| 137 | $column->uniqueName($unique_name); |
||
| 138 | $table->addUniqueKey($unique_name, $column_name); |
||
| 139 | break; |
||
| 140 | |||
| 141 | default: |
||
| 142 | $column->uniqueGroupName($unique_name); |
||
| 143 | unset($this->unique_by_table[$table_name][$column_name][0]); |
||
| 144 | $table->addUniqueKey($unique_name, $this->unique_by_table[$table_name][$column_name]); |
||
| 145 | break; |
||
| 146 | } |
||
| 147 | } |
||
| 148 | // handling usage foreign keys |
||
| 149 | if (($reference = $this->getForeignKey($table_name, $column_name)) !== false) { |
||
| 150 | $column->isForeign(true); |
||
| 151 | $column->setForeignTableName($reference[0]); |
||
| 152 | $column->setForeignColumnName($reference[1]); |
||
| 153 | |||
| 154 | $table->addForeignKey($column); |
||
| 155 | } |
||
| 156 | $table->addColumn($column); |
||
| 157 | } |
||
| 158 | // ddt($table); |
||
| 159 | $this->table_cache[$table_name] = $table; |
||
| 160 | |||
| 161 | return $this->table_cache[$table_name]; |
||
| 162 | } |
||
| 169 |