1 | <?php |
||||||
2 | /** |
||||||
3 | * Transaction program |
||||||
4 | * User: moyo |
||||||
5 | * Date: 03/11/2017 |
||||||
6 | * Time: 11:43 AM |
||||||
7 | */ |
||||||
8 | |||||||
9 | namespace Carno\Database\Programs; |
||||||
10 | |||||||
11 | use Carno\Database\Contracts\Executable; |
||||||
12 | use Carno\Database\Contracts\Transaction as TransAPI; |
||||||
13 | use Carno\Promise\Promised; |
||||||
14 | |||||||
15 | class Transaction implements TransAPI, Executable |
||||||
16 | { |
||||||
17 | /** |
||||||
18 | * @var TransAPI|Executable |
||||||
19 | */ |
||||||
20 | private $link = null; |
||||||
21 | |||||||
22 | /** |
||||||
23 | * @var Promised |
||||||
24 | */ |
||||||
25 | private $wStart = null; |
||||||
26 | |||||||
27 | /** |
||||||
28 | * @var Promised |
||||||
29 | */ |
||||||
30 | private $wCommit = null; |
||||||
31 | |||||||
32 | /** |
||||||
33 | * @var Promised |
||||||
34 | */ |
||||||
35 | private $wRollback = null; |
||||||
36 | |||||||
37 | /** |
||||||
38 | * Transaction constructor. |
||||||
39 | * @param TransAPI $link |
||||||
40 | * @param Promised $start |
||||||
41 | * @param Promised $commit |
||||||
42 | * @param Promised $rollback |
||||||
43 | */ |
||||||
44 | public function __construct( |
||||||
45 | TransAPI $link, |
||||||
46 | Promised $start, |
||||||
47 | Promised $commit, |
||||||
48 | Promised $rollback |
||||||
49 | ) { |
||||||
50 | $this->link = $link; |
||||||
51 | |||||||
52 | $this->wStart = $start; |
||||||
53 | $this->wCommit = $commit; |
||||||
54 | $this->wRollback = $rollback; |
||||||
55 | } |
||||||
56 | |||||||
57 | /** |
||||||
58 | * @return Executable |
||||||
59 | */ |
||||||
60 | public function link() : Executable |
||||||
61 | { |
||||||
62 | return $this->link; |
||||||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||||||
63 | } |
||||||
64 | |||||||
65 | /** |
||||||
66 | * @param string $sql |
||||||
67 | * @param array $bind |
||||||
68 | * @return Promised |
||||||
69 | */ |
||||||
70 | public function execute(string $sql, array $bind = []) |
||||||
71 | { |
||||||
72 | return $this->link->execute($sql, $bind); |
||||||
0 ignored issues
–
show
The method
execute() does not exist on Carno\Database\Contracts\Transaction . Since it exists in all sub-types, consider adding an abstract or default implementation to Carno\Database\Contracts\Transaction .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
73 | } |
||||||
74 | |||||||
75 | /** |
||||||
76 | * @deprecated |
||||||
77 | * @param string $data |
||||||
78 | * @return string |
||||||
79 | */ |
||||||
80 | public function escape(string $data) : string |
||||||
81 | { |
||||||
82 | return $this->link->escape($data); |
||||||
0 ignored issues
–
show
The function
Carno\Database\Contracts\Executable::escape() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() The method
escape() does not exist on Carno\Database\Contracts\Transaction . Since it exists in all sub-types, consider adding an abstract or default implementation to Carno\Database\Contracts\Transaction .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
83 | } |
||||||
84 | |||||||
85 | /** |
||||||
86 | * @return Promised |
||||||
87 | */ |
||||||
88 | public function begin() |
||||||
89 | { |
||||||
90 | yield $this->link->begin(); |
||||||
0 ignored issues
–
show
The method
begin() does not exist on Carno\Database\Contracts\Executable . It seems like you code against a sub-type of Carno\Database\Contracts\Executable such as Carno\Database\Connectors\MySQL or Carno\Database\Programs\Transaction .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
91 | $this->wStart->resolve(); |
||||||
92 | return $this->wStart; |
||||||
93 | } |
||||||
94 | |||||||
95 | /** |
||||||
96 | * @return Promised |
||||||
97 | */ |
||||||
98 | public function commit() |
||||||
99 | { |
||||||
100 | yield $this->link->commit(); |
||||||
0 ignored issues
–
show
The method
commit() does not exist on Carno\Database\Contracts\Executable . It seems like you code against a sub-type of Carno\Database\Contracts\Executable such as Carno\Database\Connectors\MySQL or Carno\Database\Programs\Transaction .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
101 | $this->wCommit->resolve(); |
||||||
102 | return $this->wCommit; |
||||||
103 | } |
||||||
104 | |||||||
105 | /** |
||||||
106 | * @return Promised |
||||||
107 | */ |
||||||
108 | public function rollback() |
||||||
109 | { |
||||||
110 | yield $this->link->rollback(); |
||||||
0 ignored issues
–
show
The method
rollback() does not exist on Carno\Database\Contracts\Executable . It seems like you code against a sub-type of Carno\Database\Contracts\Executable such as Carno\Database\Connectors\MySQL or Carno\Database\Programs\Transaction .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
111 | $this->wRollback->resolve(); |
||||||
112 | return $this->wRollback; |
||||||
113 | } |
||||||
114 | } |
||||||
115 |