Skip to content

Commit a27a165

Browse files
committed
Fix compatiblity with orisai/stream-wrapper-contracts
1 parent 02f4120 commit a27a165

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

src/VfsStreamWrapper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public function rmdir(string $path, int $options): bool
282282
return true;
283283
}
284284

285-
public function stream_cast(int $cast_as): bool
285+
public function stream_cast(int $cast_as)
286286
{
287287
return false;
288288
}
@@ -637,7 +637,7 @@ private function getStatDefault(): array
637637
'uid' => 0,
638638
'gid' => 0,
639639
'rdev' => 0,
640-
'size' => 123,
640+
'size' => 0,
641641
'atime' => 0,
642642
'mtime' => 0,
643643
'ctime' => 0,
@@ -648,7 +648,7 @@ private function getStatDefault(): array
648648
return array_merge(array_values($assoc), $assoc);
649649
}
650650

651-
public function stream_stat(): array
651+
public function stream_stat()
652652
{
653653
assert($this->currentFile !== null);
654654
$file = $this->currentFile->getFile();

src/Wrapper/FileHandler.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Orisai\VFS\Lock;
66
use Orisai\VFS\Structure\File;
77
use Orisai\VFS\VfsStreamWrapper;
8+
use function assert;
89
use function min;
910
use function strlen;
1011
use function substr;
@@ -19,6 +20,7 @@ final class FileHandler
1920
private const ReadMode = 1,
2021
WriteMode = 2;
2122

23+
/** @var int<0, max> */
2224
private int $position = 0;
2325

2426
private int $mode = 0;
@@ -37,7 +39,8 @@ public function getFile(): File
3739

3840
/**
3941
* Writes to file and moves pointer.
40-
* Returns number of written bytes.
42+
*
43+
* @return int<0, max> number of written bytes
4144
*/
4245
public function write(string $data): int
4346
{
@@ -64,18 +67,25 @@ public function read(int $bytes): string
6467

6568
$newPosition = $this->getPosition() + $bytes;
6669
$newPosition = min($newPosition, strlen($content));
70+
assert($newPosition >= 0);
6771
$this->setPosition($newPosition);
6872

6973
$this->file->setAccessTime(time());
7074

7175
return $return;
7276
}
7377

78+
/**
79+
* @return int<0, max>
80+
*/
7481
public function getPosition(): int
7582
{
7683
return $this->position;
7784
}
7885

86+
/**
87+
* @param int<0, max> $position
88+
*/
7989
public function setPosition(int $position): void
8090
{
8191
$this->position = $position;
@@ -92,6 +102,9 @@ public function seekToEnd(): int
92102
return $position;
93103
}
94104

105+
/**
106+
* @param int<0, max> $offset
107+
*/
95108
public function offsetPosition(int $offset): void
96109
{
97110
$this->position += $offset;

tools/phpstan.baseline.neon

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
parameters:
22
ignoreErrors:
3+
-
4+
message: '#^Method Orisai\\VFS\\VfsStreamWrapper\:\:stream_stat\(\) never returns false so it can be removed from the return type\.$#'
5+
identifier: return.unusedType
6+
count: 1
7+
path: ../src/VfsStreamWrapper.php
8+
9+
-
10+
message: '#^Method Orisai\\VFS\\VfsStreamWrapper\:\:stream_stat\(\) should return array\{0\: int, 1\: int, 2\: int, 3\: int, 4\: int, 5\: int, 6\: int, 7\: int, \.\.\.\}\|false but returns non\-empty\-array\<int\|string, int\>\.$#'
11+
identifier: return.type
12+
count: 1
13+
path: ../src/VfsStreamWrapper.php
14+
15+
-
16+
message: '#^Method Orisai\\VFS\\VfsStreamWrapper\:\:url_stat\(\) should return array\{0\: int, 1\: int, 2\: int, 3\: int, 4\: int, 5\: int, 6\: int, 7\: int, \.\.\.\}\|false but returns non\-empty\-array\<int\|string, int\>\.$#'
17+
identifier: return.type
18+
count: 1
19+
path: ../src/VfsStreamWrapper.php
20+
321
-
422
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertFalse\(\) with false and ''Directory not…'' will always evaluate to true\.$#'
523
identifier: staticMethod.alreadyNarrowedType

0 commit comments

Comments
 (0)