| Conditions | 13 |
| Paths | 96 |
| Total Lines | 71 |
| Code Lines | 43 |
| 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 |
||
| 62 | * @param RequestHandlerInterface $handler |
||
| 63 | * |
||
| 64 | * @return ResponseInterface |
||
| 65 | */ |
||
| 66 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
||
| 67 | { |
||
| 68 | $this->migration_service |
||
| 69 | ->updateSchema('\Fisharebest\Webtrees\Schema', 'WT_SCHEMA_VERSION', Webtrees::SCHEMA_VERSION); |
||
| 70 | |||
| 71 | $platform = DB::getDBALConnection()->getDatabasePlatform(); |
||
| 72 | $platform->registerDoctrineTypeMapping(dbType: 'enum', doctrineType: 'string'); |
||
| 73 | |||
| 74 | $schema_manager = DB::getDBALConnection()->createSchemaManager(); |
||
| 75 | $comparator = $schema_manager->createComparator(); |
||
| 76 | $source = $schema_manager->introspectSchema(); |
||
| 77 | $target = WebtreesSchema::schema(); |
||
| 78 | |||
| 79 | // doctrine/dbal 4.0 does not have the concept of "saveSQL" |
||
| 80 | foreach ($source->getTables() as $table) { |
||
| 81 | if (!$target->hasTable($table->getName())) { |
||
| 82 | $source->dropTable($table->getName()); |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | <<<<<<< HEAD |
||
| 87 | $schema_diff = $comparator->compareSchemas(oldSchema: $source, newSchema: $target); |
||
| 88 | $queries = $platform->getAlterSchemaSQL($schema_diff); |
||
| 89 | |||
| 90 | foreach ($target->getTables() as $table) { |
||
| 91 | foreach ($table->getForeignKeys() as $foreign_key) { |
||
| 92 | // Cannot do this with self-referencing tables |
||
| 93 | if ($table->getName() !== $foreign_key->getForeignTableName()) { |
||
| 94 | $queries[] = |
||
| 95 | 'DELETE FROM ' . $table->getName() . |
||
| 96 | ' WHERE (' . implode(', ', $foreign_key->getLocalColumns()) . ')' . |
||
| 97 | ' NOT IN (' . |
||
| 98 | ' SELECT ' . implode(', ', $foreign_key->getForeignColumns()) . ' FROM ' . $foreign_key->getForeignTableName() . |
||
| 99 | ' WHERE ' . implode(' AND ', array_map(static fn (string $col): string => $col . ' IS NOT NULL ', $foreign_key->getLocalColumns())) . |
||
| 100 | ' )'; |
||
| 101 | } |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | // SQLite, PostgreSQL and SQL-Server all support DDL in transactions |
||
| 106 | if (DB::getDBALConnection()->getDriver() instanceof AbstractMySQLDriver) { |
||
| 107 | $phase = fn (string $query): int => str_contains($query, 'DROP FOREIGN KEY') ? 1 : (str_contains($query, 'FOREIGN KEY') ? 3 : 2); |
||
| 108 | usort($queries, fn (string $x, string $y): int => $phase($x) <=> $phase($y)); |
||
| 109 | ======= |
||
| 110 | $schema_diff = $comparator->compareSchemas(oldSchema: $source, newSchema: $target); |
||
| 111 | $queries = $platform->getAlterSchemaSQL(diff: $schema_diff); |
||
| 112 | |||
| 113 | // SQLite, PostgreSQL and SQL-Server all support DDL in transactions |
||
| 114 | if (DB::getDBALConnection()->getDriver() instanceof AbstractMySQLDriver) { |
||
| 115 | $queries = [ |
||
| 116 | 'SET FOREIGN_KEY_CHECKS := 0', |
||
| 117 | ...$queries, |
||
| 118 | 'SET FOREIGN_KEY_CHECKS := 1', |
||
| 119 | ]; |
||
| 120 | >>>>>>> cbed0ac0da (Create a new database abstraction layer) |
||
| 121 | } else { |
||
| 122 | $queries = [ |
||
| 123 | 'START TRANSACTION', |
||
| 124 | ...$queries, |
||
| 125 | 'COMMIT', |
||
| 126 | ]; |
||
| 127 | } |
||
| 128 | |||
| 129 | |||
| 130 | foreach ($queries as $query) { |
||
| 131 | <<<<<<< HEAD |
||
| 132 | if (str_contains($query, 'RENAME INDEX')) { |
||
| 133 | echo '<p><i>', $query, ';</i></p>'; |
||
| 165 |