| Conditions | 11 |
| Paths | 25 |
| Total Lines | 40 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 36 | public function generate(string $table, $indexes, bool $ignoreIndexNames): array |
||
| 37 | { |
||
| 38 | $singleColIndexes = collect([]); |
||
| 39 | $multiColIndexes = collect([]); |
||
| 40 | |||
| 41 | // Doctrine/Dbal doesn't return spatial information from PostgreSQL |
||
| 42 | // Use raw SQL here to create $spatial index name list. |
||
| 43 | $spatials = $this->getSpatialList($table); |
||
| 44 | |||
| 45 | foreach ($indexes as $index) { |
||
| 46 | $indexField = [ |
||
| 47 | 'field' => array_map([$this->decorator, 'addSlash'], $index->getColumns()), |
||
| 48 | 'type' => IndexType::INDEX, |
||
| 49 | 'args' => [], |
||
| 50 | ]; |
||
| 51 | |||
| 52 | if ($index->isPrimary()) { |
||
| 53 | $indexField['type'] = IndexType::PRIMARY; |
||
| 54 | } elseif ($index->isUnique()) { |
||
| 55 | $indexField['type'] = IndexType::UNIQUE; |
||
| 56 | } elseif (( |
||
| 57 | count($index->getFlags()) > 0 && $index->hasFlag('spatial') |
||
| 58 | ) || $spatials->contains($index->getName())) { |
||
| 59 | $indexField['type'] = IndexType::SPATIAL_INDEX; |
||
| 60 | } |
||
| 61 | |||
| 62 | if (!$index->isPrimary()) { |
||
| 63 | if (!$ignoreIndexNames && !$this->useLaravelStyleDefaultName($table, $index, $indexField['type'])) { |
||
| 64 | $indexField['args'][] = $this->decorateName($index->getName()); |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | if (count($index->getColumns()) === 1) { |
||
| 69 | $singleColIndexes->put($this->decorator->addSlash($index->getColumns()[0]), $indexField); |
||
| 70 | } else { |
||
| 71 | $multiColIndexes->push($indexField); |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | return ['single' => $singleColIndexes, 'multi' => $multiColIndexes]; |
||
| 76 | } |
||
| 116 |