Total Complexity | 11 |
Total Lines | 53 |
Duplicated Lines | 0 % |
Coverage | 80% |
Changes | 4 | ||
Bugs | 2 | Features | 0 |
1 | <?php |
||
15 | final class SyncTables implements GeneratorInterface |
||
16 | { |
||
17 | // Readonly tables must be included form the sync with database |
||
18 | public const READONLY_SCHEMA = 'readonlySchema'; |
||
19 | |||
20 | /** |
||
21 | * |
||
22 | * @throws SyncException |
||
23 | * |
||
24 | */ |
||
25 | public function run(Registry $registry): Registry |
||
26 | { |
||
27 | 16 | foreach ($this->getRegistryDbList($registry) as $dbName) { |
|
28 | $reflector = new Reflector(); |
||
29 | 16 | ||
30 | 16 | foreach ($registry as $regEntity) { |
|
31 | if ( |
||
32 | 16 | !$registry->hasTable($regEntity) |
|
33 | || $registry->getDatabase($regEntity) !== $dbName |
||
34 | 16 | || $regEntity->getOptions()->has(self::READONLY_SCHEMA) |
|
35 | 16 | ) { |
|
36 | 16 | continue; |
|
37 | } |
||
38 | |||
39 | $reflector->addTable($registry->getTableSchema($regEntity)); |
||
40 | } |
||
41 | 16 | ||
42 | try { |
||
43 | $reflector->run(); |
||
44 | } catch (\Throwable $e) { |
||
45 | 16 | throw new SyncException($e->getMessage(), (int) $e->getCode(), $e); |
|
46 | } |
||
47 | } |
||
48 | |||
49 | return $registry; |
||
50 | } |
||
51 | 16 | ||
52 | private function getRegistryDbList(Registry $registry): array |
||
68 | 16 | } |
|
69 | } |
||
70 |