-
Notifications
You must be signed in to change notification settings - Fork 426
/
filesystem-functions.php
68 lines (55 loc) · 1.11 KB
/
filesystem-functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace FilesystemFunctions;
use function PHPStan\Testing\assertType;
class Bug5461
{
public function run(): void
{
$fh = fopen('foo.txt', 'r');
if ($fh === false) {
throw new \InvalidArgumentException('Could not open file');
}
while (!feof($fh)) {
$data = (string)fread($fh, 1024);
assertType('bool', feof($fh));
}
fclose($fh);
}
}
class MoreTests
{
public function test1(): void
{
if (fopen('foo.txt', 'r') === false) {
assertType('resource|false', fopen('foo.txt', 'r'));
}
}
/**
* @param resource $fh
*/
public function test2($fh): void
{
if (fread($fh, 4) === 'data') {
assertType('string|false', fread($fh, 4));
}
}
/**
* @param resource $fh
*/
public function test3($fh): void
{
if (ftell($fh) === 0) {
assertType('0', ftell($fh));
fseek($fh, 10);
assertType('int|false', ftell($fh));
}
}
public function test4(string $path): void
{
if (file_get_contents($path) === 'data') {
assertType('\'data\'', file_get_contents($path));
file_put_contents($path, 'other');
assertType('string|false', file_get_contents($path));
}
}
}