@@ -60,19 +60,19 @@ final class PgSqlHandle extends AbstractHandle
6060 private array $ statements = [];
6161
6262 /**
63- * @param \PgSql\Connection $handle PostgreSQL connection handle.
63+ * @param \PgSql\Connection $connection PostgreSQL connection handle.
6464 * @param resource $socket PostgreSQL connection stream socket.
6565 * @param string $id Connection identifier for determining which cached type table to use.
6666 */
6767 public function __construct (
68- \PgSql \Connection $ handle ,
68+ \PgSql \Connection $ connection ,
6969 $ socket ,
7070 private readonly string $ id ,
7171 PostgresConfig $ config ,
7272 ) {
73- $ this ->handle = $ handle ;
73+ $ this ->handle = $ connection ;
7474
75- $ handle = &$ this ->handle ;
75+ $ connection = &$ this ->handle ;
7676 $ lastUsedAt = &$ this ->lastUsedAt ;
7777 $ deferred = &$ this ->pendingOperation ;
7878 $ listeners = &$ this ->listeners ;
@@ -82,10 +82,10 @@ public function __construct(
8282 &$ deferred ,
8383 &$ lastUsedAt ,
8484 &$ listeners ,
85- &$ handle ,
85+ &$ connection ,
8686 $ onClose ,
8787 ): void {
88- if (!$ handle ) {
88+ if (!$ connection ) {
8989 EventLoop::disable ($ watcher );
9090 return ;
9191 }
@@ -95,15 +95,15 @@ public function __construct(
9595 \set_error_handler (self ::getErrorHandler ());
9696
9797 try {
98- if (\pg_connection_status ($ handle ) !== \PGSQL_CONNECTION_OK ) {
98+ if (\pg_connection_status ($ connection ) !== \PGSQL_CONNECTION_OK ) {
9999 throw new SqlConnectionException ("The connection closed during the operation " );
100100 }
101101
102- if (!\pg_consume_input ($ handle )) {
103- throw new SqlConnectionException (\pg_last_error ($ handle ));
102+ if (!\pg_consume_input ($ connection )) {
103+ throw new SqlConnectionException (\pg_last_error ($ connection ));
104104 }
105105
106- while ($ result = \pg_get_notify ($ handle , \PGSQL_ASSOC )) {
106+ while ($ result = \pg_get_notify ($ connection , \PGSQL_ASSOC )) {
107107 $ channel = $ result ["message " ];
108108
109109 if (!isset ($ listeners [$ channel ])) {
@@ -118,18 +118,18 @@ public function __construct(
118118 return ; // No active query, only notification listeners.
119119 }
120120
121- if (\pg_connection_busy ($ handle )) {
121+ if (\pg_connection_busy ($ connection )) {
122122 return ;
123123 }
124124
125- $ deferred ->complete (\pg_get_result ($ handle ));
125+ $ deferred ->complete (\pg_get_result ($ connection ));
126126 $ deferred = null ;
127127
128128 if (empty ($ listeners )) {
129129 EventLoop::unreference ($ watcher );
130130 }
131131 } catch (SqlConnectionException $ exception ) {
132- $ handle = null ; // Marks connection as dead.
132+ $ connection = null ; // Marks connection as dead.
133133 EventLoop::disable ($ watcher );
134134
135135 self ::shutdown ($ listeners , $ deferred , $ onClose , $ exception );
@@ -141,29 +141,29 @@ public function __construct(
141141 $ await = EventLoop::onWritable ($ socket , static function (string $ watcher ) use (
142142 &$ deferred ,
143143 &$ listeners ,
144- &$ handle ,
144+ &$ connection ,
145145 $ onClose ,
146146 ): void {
147- if (!$ handle ) {
147+ if (!$ connection ) {
148148 EventLoop::disable ($ watcher );
149149 return ;
150150 }
151151
152152 \set_error_handler (self ::getErrorHandler ());
153153
154154 try {
155- $ flush = \pg_flush ($ handle );
155+ $ flush = \pg_flush ($ connection );
156156 if ($ flush === 0 ) {
157157 return ; // Not finished sending data, listen again.
158158 }
159159
160160 EventLoop::disable ($ watcher );
161161
162162 if ($ flush === false ) {
163- throw new SqlConnectionException (\pg_last_error ($ handle ));
163+ throw new SqlConnectionException (\pg_last_error ($ connection ));
164164 }
165165 } catch (SqlConnectionException $ exception ) {
166- $ handle = null ; // Marks connection as dead.
166+ $ connection = null ; // Marks connection as dead.
167167 EventLoop::disable ($ watcher );
168168
169169 self ::shutdown ($ listeners , $ deferred , $ onClose , $ exception );
@@ -211,7 +211,7 @@ private function fetchTypes(): Future
211211 try {
212212 $ result = $ queryDeferred ->getFuture ()->await ();
213213 if (\pg_result_status ($ result ) !== \PGSQL_TUPLES_OK ) {
214- throw new SqlException (\pg_result_error ($ result ));
214+ throw new SqlException (\pg_result_error ($ result ) ?: ' Unknown result error ' );
215215 }
216216
217217 $ types = [];
@@ -284,6 +284,7 @@ private function send(\Closure $function, mixed ...$args): mixed
284284 }
285285
286286 while ($ result = \pg_get_result ($ this ->handle )) {
287+ /** @psalm-suppress UnusedFunctionCall */
287288 \pg_free_result ($ result );
288289 }
289290
@@ -337,7 +338,7 @@ private function createResult(\PgSql\Result $result, string $sql): PostgresResul
337338 foreach (self ::DIAGNOSTIC_CODES as $ fieldCode => $ description ) {
338339 $ diagnostics [$ description ] = \pg_result_error_field ($ result , $ fieldCode );
339340 }
340- $ message = \pg_result_error ($ result );
341+ $ message = \pg_result_error ($ result ) ?: ' Unknown result error ' ;
341342 \set_error_handler (self ::getErrorHandler ());
342343 try {
343344 while (\pg_connection_busy ($ this ->handle ) && \pg_get_result ($ this ->handle )) {
@@ -350,7 +351,7 @@ private function createResult(\PgSql\Result $result, string $sql): PostgresResul
350351
351352 case \PGSQL_BAD_RESPONSE :
352353 $ this ->close ();
353- throw new SqlException (\pg_result_error ($ result ));
354+ throw new SqlException (\pg_result_error ($ result ) ?: ' Unknown result error ' );
354355
355356 default :
356357 // @codeCoverageIgnoreStart
@@ -407,7 +408,7 @@ public function statementDeallocate(string $name): void
407408 }
408409
409410 $ future = $ storage ->future ;
410- $ storage ->future = async (function () use ($ future , $ storage , $ name ): void {
411+ $ storage ->future = async (function () use ($ future , $ name ): void {
411412 if (!$ future ->await ()) {
412413 return ; // Statement already deallocated.
413414 }
@@ -493,17 +494,21 @@ public function prepare(string $sql): PostgresStatement
493494 foreach (self ::DIAGNOSTIC_CODES as $ fieldCode => $ description ) {
494495 $ diagnostics [$ description ] = \pg_result_error_field ($ result , $ fieldCode );
495496 }
496- throw new PostgresQueryError (\pg_result_error ($ result ), $ diagnostics , $ sql );
497+ throw new PostgresQueryError (
498+ \pg_result_error ($ result ) ?: 'Unknown result error ' ,
499+ $ diagnostics ,
500+ $ sql ,
501+ );
497502
498503 case \PGSQL_BAD_RESPONSE :
499- throw new SqlException (\pg_result_error ($ result ));
504+ throw new SqlException (\pg_result_error ($ result ) ?: ' Unknown result error ' );
500505
501506 default :
502507 // @codeCoverageIgnoreStart
503508 throw new SqlException (\sprintf (
504509 "Unknown result status: %d; error: %s " ,
505510 $ status ,
506- \pg_result_error ($ result ) ?: 'none ' ,
511+ \pg_result_error ($ result ) ?: 'Unknown result error ' ,
507512 ));
508513 // @codeCoverageIgnoreEnd
509514 }
0 commit comments