Skip to content

Commit

Permalink
Fix Psalm issues identified by new version
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Dec 5, 2023
1 parent 8efff4b commit a2c41dc
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
14 changes: 12 additions & 2 deletions src/Internal/PgSqlHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public function __construct(
) {
$this->handle = $handle;

$this->types = (self::$typeCache[$id] ??= self::fetchTypes($handle));

$handle = &$this->handle;
$lastUsedAt = &$this->lastUsedAt;
$deferred = &$this->pendingOperation;
Expand All @@ -75,6 +77,11 @@ public function __construct(
&$handle,
$onClose,
): void {
if (!$handle) {
EventLoop::disable($watcher);
return;
}

$lastUsedAt = \time();

\set_error_handler(self::getErrorHandler());
Expand Down Expand Up @@ -129,6 +136,11 @@ public function __construct(
&$handle,
$onClose,
): void {
if (!$handle) {
EventLoop::disable($watcher);
return;
}

\set_error_handler(self::getErrorHandler());

try {
Expand Down Expand Up @@ -156,8 +168,6 @@ public function __construct(
EventLoop::disable($await);

parent::__construct($config, $poll, $await, $onClose);

$this->types = (self::$typeCache[$id] ??= self::fetchTypes($handle));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/PqHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function __construct(pq\Connection $handle, PostgresConfig $config)
$onClose,
): void {
try {
if (!$handle->flush()) {
if (!$handle?->flush()) {
return; // Not finished sending data, continue polling for writability.
}
} catch (pq\Exception $exception) {
Expand Down
1 change: 1 addition & 0 deletions src/Internal/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

/**
* @internal
* @psalm-suppress ReferenceConstraintViolation
*
* @param string $sql SQL statement with named and unnamed placeholders.
* @param-out list<int|string> $names Array of parameter positions mapped to names and/or indexed locations.
Expand Down
15 changes: 13 additions & 2 deletions src/PgSqlConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,19 @@ public static function connect(PostgresConfig $config, ?Cancellation $cancellati
$hash = \sha1($config->getHost() . $config->getPort() . $config->getUser());

$deferred = new DeferredFuture();
/** @psalm-suppress MissingClosureParamType $resource is a resource and cannot be inferred in this context */
$callback = static function (string $callbackId, $resource) use (&$poll, &$await, $connection, $config, $deferred, $hash): void {

/**
* @psalm-suppress MissingClosureParamType $resource is a resource and cannot be inferred in this context.
* @psalm-suppress UndefinedVariable $poll is defined below.
*/
$callback = static function (string $callbackId, $resource) use (
&$poll,
&$await,
$connection,
$config,
$deferred,
$hash,
): void {
switch ($result = \pg_connect_poll($connection)) {
case \PGSQL_POLLING_READING:
case \PGSQL_POLLING_WRITING:
Expand Down
4 changes: 3 additions & 1 deletion src/PqConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public static function connect(PostgresConfig $config, ?Cancellation $cancellati
$connection->unbuffered = true;

$deferred = new DeferredFuture();
$callback = function () use (&$poll, &$await, $connection, $config, $deferred): void {

/** @psalm-suppress UndefinedVariable $poll is defined below. */
$callback = static function () use (&$poll, &$await, $connection, $config, $deferred): void {
switch ($result = $connection->poll()) {
case pq\Connection::POLLING_READING:
case pq\Connection::POLLING_WRITING:
Expand Down

0 comments on commit a2c41dc

Please sign in to comment.