1010use PDOStatement ;
1111
1212class QueryStatement implements DatabaseStatement {
13- /** @var PDOStatement<mixed> */
14- private $ statement ;
15- /** @var QueryLoggers */
16- private $ queryLoggers ;
17- /** @var string */
18- private $ query ;
19- /** @var MySQLExceptionInterpreter */
20- private $ exceptionInterpreter ;
21-
2213 /**
2314 * @param PDOStatement<mixed> $stmt
2415 * @param string $query
2516 * @param MySQLExceptionInterpreter $exceptionInterpreter
2617 * @param QueryLoggers $queryLoggers
2718 */
28- public function __construct (PDOStatement $ stmt , string $ query , MySQLExceptionInterpreter $ exceptionInterpreter , QueryLoggers $ queryLoggers ) {
29- $ this -> statement = $ stmt;
30- $ this -> queryLoggers = $ queryLoggers ;
31- $ this -> query = $ query ;
32- $ this -> exceptionInterpreter = $ exceptionInterpreter ;
33- }
19+ public function __construct (
20+ private PDOStatement $ stmt,
21+ private string $ query ,
22+ private MySQLExceptionInterpreter $ exceptionInterpreter ,
23+ private QueryLoggers $ queryLoggers
24+ ) { }
3425
3526 /**
3627 * @return PDOStatement<mixed>
3728 */
3829 public function getStatement (): PDOStatement {
39- return $ this ->statement ;
30+ return $ this ->stmt ;
4031 }
4132
4233 /**
@@ -53,7 +44,7 @@ public function setFetchMode(int $mode = PDO::FETCH_ASSOC, $arg0 = null, ?array
5344 if ($ arg1 !== null ) {
5445 $ args [] = $ arg1 ;
5546 }
56- $ this ->statement ->setFetchMode (...$ args );
47+ $ this ->stmt ->setFetchMode (...$ args );
5748 return $ this ;
5849 }
5950
@@ -65,7 +56,7 @@ public function setFetchMode(int $mode = PDO::FETCH_ASSOC, $arg0 = null, ?array
6556 public function execute (array $ params = []) {
6657 $ this ->exceptionHandler (function () use ($ params ) {
6758 $ this ->queryLoggers ->logRegion ($ this ->query , function () use ($ params ) {
68- $ response = $ this ->statement ->execute ($ params );
59+ $ response = $ this ->stmt ->execute ($ params );
6960 if (!$ response ) {
7061 throw new SqlException ('Execution returned with "false". ' );
7162 }
@@ -83,9 +74,9 @@ public function execute(array $params = []) {
8374 public function fetchAll ($ fetchStyle = PDO ::FETCH_ASSOC , $ fetchArgument = null , array $ ctorArgs = []): array {
8475 $ result = $ x = $ this ->exceptionHandler (function () use ($ fetchStyle , $ fetchArgument , $ ctorArgs ) {
8576 if ($ fetchArgument !== null ) {
86- return $ this ->statement ->fetchAll ($ fetchStyle , $ fetchArgument , ...$ ctorArgs );
77+ return $ this ->stmt ->fetchAll ($ fetchStyle , $ fetchArgument , ...$ ctorArgs );
8778 }
88- return $ this ->statement ->fetchAll ($ fetchStyle );
79+ return $ this ->stmt ->fetchAll ($ fetchStyle );
8980 });
9081 /** @var array<mixed, mixed>|false $x */
9182 if ($ x === false ) {
@@ -101,29 +92,29 @@ public function fetchAll($fetchStyle = PDO::FETCH_ASSOC, $fetchArgument = null,
10192 * @return mixed
10293 */
10394 public function fetch ($ fetchStyle = PDO ::FETCH_ASSOC , $ cursorOrientation = PDO ::FETCH_ORI_NEXT , $ cursorOffset = 0 ) {
104- return $ this ->exceptionHandler (fn () => $ this ->statement ->fetch ($ fetchStyle , $ cursorOrientation , $ cursorOffset ));
95+ return $ this ->exceptionHandler (fn () => $ this ->stmt ->fetch ($ fetchStyle , $ cursorOrientation , $ cursorOffset ));
10596 }
10697
10798 /**
10899 * @param int $columnNo
109100 * @return mixed
110101 */
111102 public function fetchColumn ($ columnNo = 0 ) {
112- return $ this ->exceptionHandler (fn () => $ this ->statement ->fetchColumn ($ columnNo ));
103+ return $ this ->exceptionHandler (fn () => $ this ->stmt ->fetchColumn ($ columnNo ));
113104 }
114105
115106 /**
116107 * @return bool
117108 */
118109 public function closeCursor (): bool {
119- return $ this ->exceptionHandler (fn () => $ this ->statement ->closeCursor ());
110+ return $ this ->exceptionHandler (fn () => $ this ->stmt ->closeCursor ());
120111 }
121112
122113 /**
123114 * @return int
124115 */
125116 public function columnCount (): int {
126- return $ this ->exceptionHandler (fn () => $ this ->statement ->columnCount ());
117+ return $ this ->exceptionHandler (fn () => $ this ->stmt ->columnCount ());
127118 }
128119
129120 /**
@@ -132,7 +123,7 @@ public function columnCount(): int {
132123 */
133124 public function getColumnMeta (int $ columnNo ): ?array {
134125 return $ this ->exceptionHandler (function () use ($ columnNo ) {
135- $ columnMeta = $ this ->statement ->getColumnMeta ($ columnNo );
126+ $ columnMeta = $ this ->stmt ->getColumnMeta ($ columnNo );
136127 if ($ columnMeta === false ) {
137128 return null ;
138129 }
0 commit comments