1 | <?php |
||
11 | class Transaction |
||
12 | { |
||
13 | /** |
||
14 | * @var string|TransactionPDO Connection to database |
||
15 | */ |
||
16 | private static $connection; |
||
17 | |||
18 | /** |
||
19 | * Set connection name to access for Database Engine |
||
20 | * |
||
21 | * @param $connection |
||
22 | * |
||
23 | * @return bool True if success |
||
24 | */ |
||
25 | public static function setConnection($connection) : bool |
||
35 | |||
36 | /** |
||
37 | * Get connection to Database, either from string, or TransactionPDO instance |
||
38 | * |
||
39 | * @param string|TransactionPDO $connection |
||
40 | * |
||
41 | * @return TransactionPDO|bool |
||
42 | */ |
||
43 | private static function getConnection($connection = null) |
||
51 | |||
52 | /** |
||
53 | * Begin transaction on connection |
||
54 | * |
||
55 | * @param string|TransactionPDO $connection |
||
56 | * |
||
57 | * @return bool |
||
58 | */ |
||
59 | public static function begin($connection = null) : bool |
||
63 | |||
64 | /** |
||
65 | * Commit transaction on connection |
||
66 | * |
||
67 | * @param string|TransactionPDO $connection |
||
68 | * |
||
69 | * @return bool |
||
70 | */ |
||
71 | public static function commit($connection = null) : bool |
||
75 | |||
76 | /** |
||
77 | * Rollback transaction on connection |
||
78 | * |
||
79 | * @param string|TransactionPDO $connection |
||
80 | * |
||
81 | * @throws \PDOException |
||
82 | * @return bool |
||
83 | */ |
||
84 | public static function rollback($connection = null) : bool |
||
88 | |||
89 | /** |
||
90 | * Perform some callback while transaction execution |
||
91 | * |
||
92 | * @param Closure $callback |
||
93 | * @param string|TransactionPDO $connection |
||
94 | * |
||
95 | * @throws LogicException |
||
96 | * @throws TransactionException |
||
97 | */ |
||
98 | public static function perform(Closure $callback, $connection = null) |
||
119 | |||
120 | /** |
||
121 | * Try to perform callback while transaction execution several times |
||
122 | * |
||
123 | * @param Closure $callback |
||
124 | * @param int $attempts |
||
125 | * @param null $connection |
||
126 | * |
||
127 | * @return bool |
||
128 | * @throws TransactionException |
||
129 | */ |
||
130 | public static function attempt(Closure $callback, int $attempts = 1, $connection = null) |
||
149 | } |
||
150 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.