Total Complexity | 6 |
Total Lines | 85 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
23 | abstract class TransactionalMigration extends Migration |
||
24 | { |
||
25 | /** |
||
26 | * @inheritDoc |
||
27 | * |
||
28 | * @throws Throwable |
||
29 | */ |
||
30 | public function run(): void |
||
31 | { |
||
32 | $orm = $this->orm; |
||
33 | |||
34 | try { |
||
35 | $orm->ensureTransaction(); |
||
36 | |||
37 | $this->runMigration(); |
||
38 | |||
39 | $orm->commit(); |
||
40 | } catch (Throwable $exception) { |
||
41 | $orm->rollback(); |
||
42 | |||
43 | $this->runFailure($exception); |
||
44 | |||
45 | throw $exception; |
||
46 | } |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @inheritDoc |
||
51 | * |
||
52 | * @throws Throwable |
||
53 | */ |
||
54 | public function rollback(): void |
||
55 | { |
||
56 | $orm = $this->orm; |
||
57 | |||
58 | try { |
||
59 | $orm->ensureTransaction(); |
||
60 | |||
61 | $this->rollbackMigration(); |
||
62 | |||
63 | $orm->commit(); |
||
64 | } catch (Throwable $exception) { |
||
65 | $orm->rollback(); |
||
66 | |||
67 | $this->rollbackFailure($exception); |
||
68 | |||
69 | throw $exception; |
||
70 | } |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * Do on run failure. |
||
75 | * |
||
76 | * @param Throwable $exception The exception |
||
77 | * |
||
78 | * @return void |
||
79 | */ |
||
80 | protected function runFailure(Throwable $exception): void |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Do on rollback failure. |
||
86 | * |
||
87 | * @param Throwable $exception The exception |
||
88 | * |
||
89 | * @return void |
||
90 | */ |
||
91 | protected function rollbackFailure(Throwable $exception): void |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * Run the migration. |
||
97 | * |
||
98 | * @return void |
||
99 | */ |
||
100 | abstract protected function runMigration(): void; |
||
101 | |||
102 | /** |
||
103 | * Rollback the migration. |
||
104 | * |
||
105 | * @return void |
||
106 | */ |
||
107 | abstract protected function rollbackMigration(): void; |
||
108 | } |
||
109 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.