| Conditions | 12 |
| Paths | 96 |
| Total Lines | 64 |
| Code Lines | 37 |
| 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 |
||
| 74 | public function checkAuditTable(AbstractSchemaManager $schemaManager, Table $table): array |
||
| 75 | { |
||
| 76 | $columns = $schemaManager->listTableColumns($table->getName()); |
||
| 77 | $expected = $this->manager->getHelper()->getAuditTableColumns(); |
||
| 78 | |||
| 79 | $add = []; |
||
| 80 | $update = []; |
||
| 81 | $remove = []; |
||
| 82 | $processed = []; |
||
| 83 | |||
| 84 | foreach ($columns as $column) { |
||
| 85 | if (array_key_exists($column->getName(), $expected)) { |
||
| 86 | // column is part of expected columns, check its properties |
||
| 87 | if ($column->getType()->getName() !== $expected[$column->getName()]['type']) { |
||
| 88 | // column type is different |
||
| 89 | $update[] = [ |
||
| 90 | 'column' => $column, |
||
| 91 | 'metadata' => $expected[$column->getName()], |
||
| 92 | ]; |
||
| 93 | } else { |
||
| 94 | foreach ($expected[$column->getName()]['options'] as $key => $value) { |
||
| 95 | $method = 'get'.ucfirst($key); |
||
| 96 | if (method_exists($column, $method)) { |
||
| 97 | if ($value !== $column->{$method}()) { |
||
| 98 | $update[] = [ |
||
| 99 | 'column' => $column, |
||
| 100 | 'metadata' => $expected[$column->getName()], |
||
| 101 | ]; |
||
| 102 | } |
||
| 103 | } |
||
| 104 | } |
||
| 105 | } |
||
| 106 | } else { |
||
| 107 | // column is not part of expected columns so it has to be removed |
||
| 108 | $remove[] = [ |
||
| 109 | 'column' => $column, |
||
| 110 | ]; |
||
| 111 | } |
||
| 112 | |||
| 113 | $processed[] = $column->getName(); |
||
| 114 | } |
||
| 115 | |||
| 116 | foreach ($expected as $column => $struct) { |
||
| 117 | if (!\in_array($column, $processed, true)) { |
||
| 118 | $add[] = [ |
||
| 119 | 'column' => $column, |
||
| 120 | 'metadata' => $struct, |
||
| 121 | ]; |
||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | $operations = []; |
||
| 126 | |||
| 127 | if (!empty($add)) { |
||
| 128 | $operations['add'] = $add; |
||
| 129 | } |
||
| 130 | if (!empty($update)) { |
||
| 131 | $operations['update'] = $update; |
||
| 132 | } |
||
| 133 | if (!empty($remove)) { |
||
| 134 | $operations['remove'] = $remove; |
||
| 135 | } |
||
| 136 | |||
| 137 | return $operations; |
||
| 138 | } |
||
| 172 |