diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-07-30 07:32:58 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-07-30 07:32:58 +0900 |
| commit | 7f3246e4582a488327f2a9da01111db1a4a32b91 (patch) | |
| tree | c37f919e41949d1b482aaae4bedbdd2f65b5baef /src/Stream/FileStream.php | |
| parent | 6f18d4c860f16f094e9b3dececeb47be2a94d585 (diff) | |
| download | php-waddiwasi-7f3246e4582a488327f2a9da01111db1a4a32b91.tar.gz php-waddiwasi-7f3246e4582a488327f2a9da01111db1a4a32b91.tar.zst php-waddiwasi-7f3246e4582a488327f2a9da01111db1a4a32b91.zip | |
chore: enable common ruleset of ecs
Diffstat (limited to 'src/Stream/FileStream.php')
| -rw-r--r-- | src/Stream/FileStream.php | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/Stream/FileStream.php b/src/Stream/FileStream.php index 308f617..2f21739 100644 --- a/src/Stream/FileStream.php +++ b/src/Stream/FileStream.php @@ -30,7 +30,7 @@ final class FileStream implements StreamInterface ) { $fp = fopen($path, 'rb'); if ($fp === false) { - throw new IoException("Failed to open file: $path"); + throw new IoException("Failed to open file: {$path}"); } $this->fp = $fp; } @@ -47,12 +47,10 @@ final class FileStream implements StreamInterface $this->peekedByte = null; if ($bytes === 1) { return $first; - } else { - return $first . $this->doRead($bytes - 1); } - } else { - return $this->doRead($bytes); + return $first . $this->doRead($bytes - 1); } + return $this->doRead($bytes); } public function readByte(): int @@ -82,9 +80,9 @@ final class FileStream implements StreamInterface { $ret = ftell($this->fp); if ($ret === false) { - throw new IoException("Failed to get current position in file: $this->path"); + throw new IoException("Failed to get current position in file: {$this->path}"); } - assert(0 <= $ret); + assert($ret >= 0); return $ret; } @@ -114,10 +112,10 @@ final class FileStream implements StreamInterface { $result = fread($this->fp, $bytes); if ($result === false) { - throw new IoException("Failed to read from file: $this->path"); + throw new IoException("Failed to read from file: {$this->path}"); } if (strlen($result) < $bytes) { - throw new UnexpectedEofException(sprintf("Unexpected EOF while reading from file: %s (%d bytes expected, %d bytes read)", $this->path, $bytes, strlen($result))); + throw new UnexpectedEofException(sprintf('Unexpected EOF while reading from file: %s (%d bytes expected, %d bytes read)', $this->path, $bytes, strlen($result))); } return $result; } |
