| Conditions | 6 |
| Paths | 24 |
| Total Lines | 55 |
| Code Lines | 34 |
| 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 |
||
| 63 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
||
| 64 | { |
||
| 65 | $this->migration_service |
||
| 66 | ->updateSchema('\Fisharebest\Webtrees\Schema', 'WT_SCHEMA_VERSION', Webtrees::SCHEMA_VERSION); |
||
| 67 | |||
| 68 | $platform = DB::getDBALConnection()->getDatabasePlatform(); |
||
| 69 | $platform->registerDoctrineTypeMapping(dbType: 'enum', doctrineType: 'string'); |
||
| 70 | |||
| 71 | $schema_manager = DB::getDBALConnection()->createSchemaManager(); |
||
| 72 | $comparator = $schema_manager->createComparator(); |
||
| 73 | $source = $schema_manager->introspectSchema(); |
||
| 74 | $target = WebtreesSchema::schema(); |
||
| 75 | |||
| 76 | // doctrine/dbal 4.0 does not have the concept of "saveSQL" |
||
| 77 | foreach ($source->getTables() as $table) { |
||
| 78 | if (!$target->hasTable($table->getName())) { |
||
| 79 | $source->dropTable($table->getName()); |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | $schema_diff = $comparator->compareSchemas(oldSchema: $source, newSchema: $target); |
||
| 84 | $queries = $platform->getAlterSchemaSQL(diff: $schema_diff); |
||
| 85 | |||
| 86 | // SQLite, PostgreSQL and SQL-Server all support DDL in transactions |
||
| 87 | if (DB::getDBALConnection()->getDriver() instanceof AbstractMySQLDriver) { |
||
| 88 | $queries = [ |
||
| 89 | 'SET FOREIGN_KEY_CHECKS := 0', |
||
| 90 | ...$queries, |
||
| 91 | 'SET FOREIGN_KEY_CHECKS := 1', |
||
| 92 | ]; |
||
| 93 | } else { |
||
| 94 | $queries = [ |
||
| 95 | 'START TRANSACTION', |
||
| 96 | ...$queries, |
||
| 97 | 'COMMIT', |
||
| 98 | ]; |
||
| 99 | } |
||
| 100 | |||
| 101 | |||
| 102 | foreach ($queries as $query) { |
||
| 103 | echo '<p>', $query, ';'; |
||
|
|
|||
| 104 | $t = microtime(true); |
||
| 105 | |||
| 106 | try { |
||
| 107 | DB::getDBALConnection()->executeStatement(sql: $query); |
||
| 108 | echo ' /* ', (int) (1000.8 * (microtime(true) - $t)), 'ms */'; |
||
| 109 | } catch (Throwable $ex) { |
||
| 110 | echo ' <span style="color:red">', $ex->getMessage(), '</span>'; |
||
| 111 | } |
||
| 112 | echo '</p>'; |
||
| 113 | } |
||
| 114 | |||
| 115 | exit; |
||
| 116 | |||
| 117 | return $handler->handle($request); |
||
| 118 | } |
||
| 120 |