1 | <?php |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
2 | /** |
||
3 | * Copyright MediaCT. All rights reserved. |
||
4 | * https://www.mediact.nl |
||
5 | */ |
||
6 | |||
7 | namespace Johmanx10\Transaction\Exception; |
||
8 | |||
9 | use Johmanx10\Transaction\OperationFailureInterface; |
||
10 | use Johmanx10\Transaction\OperationInterface; |
||
11 | use RuntimeException; |
||
12 | use Throwable; |
||
13 | |||
14 | class FailedRollbackException extends RuntimeException implements FailedRollbackExceptionInterface |
||
15 | { |
||
16 | /** @var OperationInterface */ |
||
17 | private $operation; |
||
18 | |||
19 | /** @var OperationFailureInterface[] */ |
||
20 | private $previousRollbacks; |
||
21 | |||
22 | /** |
||
23 | * Constructor. |
||
24 | * |
||
25 | * @param OperationInterface $operation |
||
26 | * @param int $code |
||
27 | * @param Throwable $previous |
||
28 | * @param OperationFailureInterface ...$previousRollbacks |
||
29 | */ |
||
30 | 3 | public function __construct( |
|
31 | OperationInterface $operation, |
||
32 | int $code, |
||
33 | Throwable $previous, |
||
34 | OperationFailureInterface ...$previousRollbacks |
||
35 | ) { |
||
36 | 3 | $this->operation = $operation; |
|
37 | 3 | $this->previousRollbacks = $previousRollbacks; |
|
38 | |||
39 | 3 | parent::__construct( |
|
40 | 3 | sprintf( |
|
41 | 3 | 'Failed rolling back operation #%d', |
|
42 | 3 | spl_object_id($operation) |
|
43 | ), |
||
44 | 3 | $code, |
|
45 | 3 | $previous |
|
46 | ); |
||
47 | 3 | } |
|
48 | |||
49 | /** |
||
50 | * Get the operation for which the rollback failed. |
||
51 | * |
||
52 | * @return OperationInterface |
||
53 | */ |
||
54 | 3 | public function getOperation(): OperationInterface |
|
55 | { |
||
56 | 3 | return $this->operation; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * Get the rollbacks that succeeded before the current failure. |
||
61 | * |
||
62 | * @return OperationFailureInterface[] |
||
63 | */ |
||
64 | 3 | public function getPreviousRollbacks(): array |
|
65 | { |
||
66 | 3 | return $this->previousRollbacks; |
|
67 | } |
||
68 | } |
||
69 |