| Conditions | 3 |
| Paths | 3 |
| Total Lines | 88 |
| Code Lines | 64 |
| 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 |
||
| 109 | protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { |
||
| 110 | $schemaDiff = parent::getDiff($targetSchema, $connection); |
||
| 111 | |||
| 112 | // oracle forces us to quote the identifiers |
||
| 113 | $schemaDiff->newTables = array_map(function(Table $table) { |
||
| 114 | return new Table( |
||
| 115 | $this->connection->quoteIdentifier($table->getName()), |
||
| 116 | array_map(function(Column $column) { |
||
| 117 | return $this->quoteColumn($column); |
||
| 118 | }, $table->getColumns()), |
||
| 119 | array_map(function(Index $index) { |
||
| 120 | return $this->quoteIndex($index); |
||
| 121 | }, $table->getIndexes()), |
||
| 122 | array_map(function(ForeignKeyConstraint $fck) { |
||
| 123 | return $this->quoteForeignKeyConstraint($fck); |
||
| 124 | }, $table->getForeignKeys()), |
||
| 125 | 0, |
||
| 126 | $table->getOptions() |
||
| 127 | ); |
||
| 128 | }, $schemaDiff->newTables); |
||
| 129 | |||
| 130 | $schemaDiff->removedTables = array_map(function(Table $table) { |
||
| 131 | return new Table( |
||
| 132 | $this->connection->quoteIdentifier($table->getName()), |
||
| 133 | $table->getColumns(), |
||
| 134 | $table->getIndexes(), |
||
| 135 | $table->getForeignKeys(), |
||
| 136 | 0, |
||
| 137 | $table->getOptions() |
||
| 138 | ); |
||
| 139 | }, $schemaDiff->removedTables); |
||
| 140 | |||
| 141 | foreach ($schemaDiff->changedTables as $tableDiff) { |
||
| 142 | $tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name); |
||
| 143 | |||
| 144 | $tableDiff->addedColumns = array_map(function(Column $column) { |
||
| 145 | return $this->quoteColumn($column); |
||
| 146 | }, $tableDiff->addedColumns); |
||
| 147 | |||
| 148 | foreach ($tableDiff->changedColumns as $column) { |
||
| 149 | $column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName); |
||
| 150 | // auto increment is not relevant for oracle and can anyhow not be applied on change |
||
| 151 | $column->changedProperties = array_diff($column->changedProperties, ['autoincrement', 'unsigned']); |
||
| 152 | } |
||
| 153 | // remove columns that no longer have changed (because autoincrement and unsigned are not supported) |
||
| 154 | $tableDiff->changedColumns = array_filter($tableDiff->changedColumns, function (ColumnDiff $column) { |
||
| 155 | return count($column->changedProperties) > 0; |
||
| 156 | }); |
||
| 157 | |||
| 158 | $tableDiff->removedColumns = array_map(function(Column $column) { |
||
| 159 | return $this->quoteColumn($column); |
||
| 160 | }, $tableDiff->removedColumns); |
||
| 161 | |||
| 162 | $tableDiff->renamedColumns = array_map(function(Column $column) { |
||
| 163 | return $this->quoteColumn($column); |
||
| 164 | }, $tableDiff->renamedColumns); |
||
| 165 | |||
| 166 | $tableDiff->addedIndexes = array_map(function(Index $index) { |
||
| 167 | return $this->quoteIndex($index); |
||
| 168 | }, $tableDiff->addedIndexes); |
||
| 169 | |||
| 170 | $tableDiff->changedIndexes = array_map(function(Index $index) { |
||
| 171 | return $this->quoteIndex($index); |
||
| 172 | }, $tableDiff->changedIndexes); |
||
| 173 | |||
| 174 | $tableDiff->removedIndexes = array_map(function(Index $index) { |
||
| 175 | return $this->quoteIndex($index); |
||
| 176 | }, $tableDiff->removedIndexes); |
||
| 177 | |||
| 178 | $tableDiff->renamedIndexes = array_map(function(Index $index) { |
||
| 179 | return $this->quoteIndex($index); |
||
| 180 | }, $tableDiff->renamedIndexes); |
||
| 181 | |||
| 182 | $tableDiff->addedForeignKeys = array_map(function(ForeignKeyConstraint $fkc) { |
||
| 183 | return $this->quoteForeignKeyConstraint($fkc); |
||
| 184 | }, $tableDiff->addedForeignKeys); |
||
| 185 | |||
| 186 | $tableDiff->changedForeignKeys = array_map(function(ForeignKeyConstraint $fkc) { |
||
| 187 | return $this->quoteForeignKeyConstraint($fkc); |
||
| 188 | }, $tableDiff->changedForeignKeys); |
||
| 189 | |||
| 190 | $tableDiff->removedForeignKeys = array_map(function(ForeignKeyConstraint $fkc) { |
||
| 191 | return $this->quoteForeignKeyConstraint($fkc); |
||
| 192 | }, $tableDiff->removedForeignKeys); |
||
| 193 | } |
||
| 194 | |||
| 195 | return $schemaDiff; |
||
| 196 | } |
||
| 197 | |||
| 225 |