From c29e0300a2befdb0fa5f3392d902f2ca483fa90f Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Sat, 18 Nov 2023 10:21:21 -0600 Subject: [PATCH] Upgrade Psalm to 5.x --- composer.json | 2 +- psalm.xml | 6 ++++++ src/EventLoop.php | 4 ++-- src/EventLoop/Driver.php | 4 ++-- src/EventLoop/Driver/StreamSelectDriver.php | 2 +- src/EventLoop/Driver/TracingDriver.php | 13 ++++++++++--- src/EventLoop/Internal/AbstractDriver.php | 1 + 7 files changed, 23 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 18e66e7..2c6374e 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ "ext-json": "*", "phpunit/phpunit": "^9", "jetbrains/phpstorm-stubs": "^2019.3", - "psalm/phar": "^4.7" + "psalm/phar": "^5.15" }, "autoload": { "psr-4": { diff --git a/psalm.xml b/psalm.xml index 7c63f8b..f99206e 100644 --- a/psalm.xml +++ b/psalm.xml @@ -59,6 +59,12 @@ + + + + + + diff --git a/src/EventLoop.php b/src/EventLoop.php index 347f588..1b81136 100644 --- a/src/EventLoop.php +++ b/src/EventLoop.php @@ -346,7 +346,7 @@ public static function getType(string $callbackId): CallbackType * * @param string $callbackId The callback identifier. * - * @return bool {@code true} if the callback is currently enabled, otherwise {@code false}. + * @return bool `true` if the callback is currently enabled, otherwise `false`. */ public static function isEnabled(string $callbackId): bool { @@ -358,7 +358,7 @@ public static function isEnabled(string $callbackId): bool * * @param string $callbackId The callback identifier. * - * @return bool {@code true} if the callback is currently referenced, otherwise {@code false}. + * @return bool `true` if the callback is currently referenced, otherwise `false`. */ public static function isReferenced(string $callbackId): bool { diff --git a/src/EventLoop/Driver.php b/src/EventLoop/Driver.php index 84e5e8a..80464aa 100644 --- a/src/EventLoop/Driver.php +++ b/src/EventLoop/Driver.php @@ -294,7 +294,7 @@ public function getType(string $callbackId): CallbackType; * * @param string $callbackId The callback identifier. * - * @return bool {@code true} if the callback is currently enabled, otherwise {@code false}. + * @return bool `true` if the callback is currently enabled, otherwise `false`. */ public function isEnabled(string $callbackId): bool; @@ -303,7 +303,7 @@ public function isEnabled(string $callbackId): bool; * * @param string $callbackId The callback identifier. * - * @return bool {@code true} if the callback is currently referenced, otherwise {@code false}. + * @return bool `true` if the callback is currently referenced, otherwise `false`. */ public function isReferenced(string $callbackId): bool; diff --git a/src/EventLoop/Driver/StreamSelectDriver.php b/src/EventLoop/Driver/StreamSelectDriver.php index 03b8a1b..ad413d2 100644 --- a/src/EventLoop/Driver/StreamSelectDriver.php +++ b/src/EventLoop/Driver/StreamSelectDriver.php @@ -304,7 +304,7 @@ private function selectStreams(array $read, array $write, float $timeout): void } if ($timeout > 0) { // Sleep until next timer expires. - /** @psalm-var positive-int $timeout */ + /** @psalm-suppress ArgumentTypeCoercion $timeout is positive here. */ \usleep((int) ($timeout * 1_000_000)); } } diff --git a/src/EventLoop/Driver/TracingDriver.php b/src/EventLoop/Driver/TracingDriver.php index d16ea32..6f59ad8 100644 --- a/src/EventLoop/Driver/TracingDriver.php +++ b/src/EventLoop/Driver/TracingDriver.php @@ -249,8 +249,15 @@ private function getCancelTrace(string $callbackId): string /** * Formats a stacktrace obtained via `debug_backtrace()`. * - * @param array $trace - * Output of `debug_backtrace()`. + * @param list, + * class?: class-string, + * file?: string, + * function: string, + * line?: int, + * object?: object, + * type?: string + * }> $trace Output of `debug_backtrace()`. * * @return string Formatted stacktrace. */ @@ -259,7 +266,7 @@ private function formatStacktrace(array $trace): string return \implode("\n", \array_map(static function ($e, $i) { $line = "#{$i} "; - if (isset($e["file"])) { + if (isset($e["file"], $e['line'])) { $line .= "{$e['file']}:{$e['line']} "; } diff --git a/src/EventLoop/Internal/AbstractDriver.php b/src/EventLoop/Internal/AbstractDriver.php index 3565d20..055dd4f 100644 --- a/src/EventLoop/Internal/AbstractDriver.php +++ b/src/EventLoop/Internal/AbstractDriver.php @@ -533,6 +533,7 @@ private function createLoopFiber(): void // Invoke microtasks if we have some $this->invokeCallbacks(); + /** @psalm-suppress RedundantCondition $this->stopped may be changed by $this->invokeCallbacks(). */ while (!$this->stopped) { if ($this->interrupt) { $this->invokeInterrupt();