Conditions | 5 |
Paths | 12 |
Total Lines | 55 |
Code Lines | 32 |
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 | // Workaround for https://github.com/doctrine/dbal/issues/6092 |
||
87 | $phase = static fn (string $query): int => match (true) { |
||
88 | str_contains(haystack: $query, needle: 'DROP FOREIGN KEY') => 1, |
||
89 | default => 2, |
||
90 | str_contains(haystack: $query, needle: 'FOREIGN KEY') => 3, |
||
91 | }; |
||
92 | $fn = static fn (string $query1, string $query2): int => $phase(query: $query1) <=> $phase(query: $query2); |
||
93 | usort(array: $queries, callback: $fn); |
||
94 | |||
95 | // SQLite, PostgreSQL and SQL-Server all support DDL in transactions |
||
96 | if (DB::getDBALConnection()->getDriver() instanceof AbstractMySQLDriver) { |
||
97 | $queries = [ |
||
98 | 'SET FOREIGN_KEY_CHECKS := 0', |
||
99 | ...$queries, |
||
100 | 'SET FOREIGN_KEY_CHECKS := 1', |
||
101 | ]; |
||
102 | } else { |
||
103 | $queries = [ |
||
104 | 'START TRANSACTION', |
||
105 | ...$queries, |
||
106 | 'COMMIT', |
||
107 | ]; |
||
108 | } |
||
109 | |||
110 | |||
111 | foreach ($queries as $query) { |
||
112 | DB::getDBALConnection()->executeStatement(sql: $query); |
||
113 | } |
||
114 | |||
115 | //exit; |
||
116 | |||
117 | return $handler->handle($request); |
||
118 | } |
||
120 |