Skip to content

Commit

Permalink
Fix code sniffer
Browse files Browse the repository at this point in the history
  • Loading branch information
devanych committed Nov 15, 2023
1 parent b820bdf commit 078057f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/StreamTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,15 +335,16 @@ public function getContents(): string
}

$exception = null;
$message = 'Unable to read stream contents';

set_error_handler(static function ($type, $message) use (&$exception) {
throw $exception = new RuntimeException('Unable to read stream contents: ' . $message);
set_error_handler(static function (int $errno, string $errstr) use (&$exception, $message) {
throw $exception = new RuntimeException("$message: $errstr");
});

try {
return stream_get_contents($this->resource);
} catch (Throwable $e) {
throw $e === $exception ? $e : new RuntimeException('Unable to read stream contents: ' . $e->getMessage(), 0, $e);
throw $e === $exception ? $e : new RuntimeException("$message: {$e->getMessage()}", 0, $e);
} finally {
restore_error_handler();
}
Expand Down

0 comments on commit 078057f

Please sign in to comment.