From 581537a93109a7a1839ab68da4695929853abf48 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sun, 9 Feb 2020 08:53:39 +0100 Subject: [PATCH 1/2] Make Psalm happy --- src/Util/Printer.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Util/Printer.php b/src/Util/Printer.php index 0bf67afb2ba..947089b894e 100644 --- a/src/Util/Printer.php +++ b/src/Util/Printer.php @@ -24,7 +24,7 @@ class Printer protected $autoFlush = false; /** - * @var resource + * @var resource|closed-resource */ protected $out; @@ -77,6 +77,8 @@ public function __construct($out = null) public function flush(): void { if ($this->out && \strncmp($this->outTarget, 'php://', 6) !== 0) { + \assert(\is_resource($this->out)); + \fclose($this->out); } } @@ -91,6 +93,8 @@ public function flush(): void public function incrementalFlush(): void { if ($this->out) { + \assert(\is_resource($this->out)); + \fflush($this->out); } else { \flush(); @@ -100,6 +104,8 @@ public function incrementalFlush(): void public function write(string $buffer): void { if ($this->out) { + \assert(\is_resource($this->out)); + \fwrite($this->out, $buffer); if ($this->autoFlush) { From 073d302866d4b961e02f8f25acfeccad8fdd9227 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sun, 9 Feb 2020 09:02:36 +0100 Subject: [PATCH 2/2] Fix issues identified by Psalm --- src/Util/Test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Util/Test.php b/src/Util/Test.php index 8a3d19f6fe8..9b15e5063f9 100644 --- a/src/Util/Test.php +++ b/src/Util/Test.php @@ -162,7 +162,7 @@ public static function getMissingRequirements(string $className, string $methodN if (!\version_compare(\PHP_VERSION, $required['PHP']['version'], $operator->asString())) { $missing[] = \sprintf('PHP %s %s is required.', $operator->asString(), $required['PHP']['version']); - $hint = $hint ?? 'PHP'; + $hint = 'PHP'; } } elseif (!empty($required['PHP_constraint'])) { $version = new \PharIo\Version\Version(self::sanitizeVersionNumber(\PHP_VERSION)); @@ -173,7 +173,7 @@ public static function getMissingRequirements(string $className, string $methodN $required['PHP_constraint']['constraint']->asString() ); - $hint = $hint ?? 'PHP_constraint'; + $hint = 'PHP_constraint'; } }