Skip to content

Commit

Permalink
Merge f61e236 into be9bcc4
Browse files Browse the repository at this point in the history
  • Loading branch information
dependabot[bot] committed Nov 2, 2021
2 parents be9bcc4 + f61e236 commit 43f71bd
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 44 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -38,7 +38,7 @@
"nikic/php-parser": "^4.4"
},
"require-dev": {
"phpstan/phpstan": "^0.12",
"phpstan/phpstan": "^0.12 || ^1.0",
"phpunit/phpunit": "^8.5 || ^9.3",
"squizlabs/php_codesniffer": "^3.5"
},
Expand Down
4 changes: 0 additions & 4 deletions phpstan.neon.dist
@@ -1,6 +1,2 @@
parameters:
level: max
ignoreErrors:
- message: '/Parameter \#3 \$microseconds of function stream_set_timeout expects int, int\|null given./'
path: src/FileStreamWrapper.php
count: 1
55 changes: 37 additions & 18 deletions src/FileStreamWrapper.php
Expand Up @@ -10,6 +10,7 @@

namespace AdrianSuter\Autoload\Override;

use InvalidArgumentException;
use RuntimeException;

use function chgrp;
Expand All @@ -26,6 +27,8 @@
use function fstat;
use function ftruncate;
use function fwrite;
use function is_int;
use function is_null;
use function is_resource;
use function is_string;
use function lstat;
Expand Down Expand Up @@ -81,7 +84,7 @@ public function dir_closedir(): bool
* Open directory handle.
*
* @param string $path
* @param int $options
* @param int $options
*
* @return bool
* @noinspection PhpUnusedParameterInspection
Expand Down Expand Up @@ -147,8 +150,8 @@ public function dir_rewinddir(): bool
* Create a directory.
*
* @param string $path
* @param int $mode
* @param int $options
* @param int $mode
* @param int $options
*
* @return bool
*/
Expand Down Expand Up @@ -197,7 +200,7 @@ public function rename(string $path_from, string $path_to): bool
* Remove a directory.
*
* @param string $path
* @param int $options
* @param int $options
*
* @return bool
* @noinspection PhpUnusedParameterInspection
Expand Down Expand Up @@ -237,6 +240,7 @@ public function stream_cast(int $cast_as)

/**
* Close a resource.
*
* @noinspection PhpUnused
*/
public function stream_close(): void
Expand Down Expand Up @@ -310,9 +314,9 @@ public function stream_lock(int $operation): bool
/**
* Change stream metadata.
*
* @param string $path
* @param int $option
* @param mixed $value
* @param string $path
* @param int $option
* @param array<int|null>|string|int $value
*
* @return bool
* @noinspection PhpUnused
Expand All @@ -324,24 +328,34 @@ public function stream_metadata(string $path, int $option, $value): bool
$r = false;
switch ($option) {
case STREAM_META_TOUCH:
/** @var array<int|null> $value */
if (!isset($value[0]) || is_null($value[0])) {
$r = touch($path);
} else {
$r = touch($path, $value[0], $value[1]);
$r = touch($path, (int)$value[0], (int)$value[1]);
}
break;

case STREAM_META_OWNER_NAME:
case STREAM_META_OWNER:
if (!is_int($value) && !is_string($value)) {
throw new InvalidArgumentException('Parameter #3 is expected to be an `int|string`.');
}
$r = chown($path, $value);
break;

case STREAM_META_GROUP_NAME:
case STREAM_META_GROUP:
if (!is_int($value) && !is_string($value)) {
throw new InvalidArgumentException('Parameter #3 is expected to be an `int|string`.');
}
$r = chgrp($path, $value);
break;

case STREAM_META_ACCESS:
if (!is_int($value)) {
throw new InvalidArgumentException('Parameter #3 is expected to be an `int`.');
}
$r = chmod($path, $value);
break;
}
Expand All @@ -355,9 +369,9 @@ public function stream_metadata(string $path, int $option, $value): bool
/**
* Open file or URL.
*
* @param string $path
* @param string $mode
* @param int $options
* @param string $path
* @param string $mode
* @param int $options
* @param string|null $opened_path
*
* @return bool
Expand Down Expand Up @@ -403,7 +417,8 @@ public function stream_open(string $path, string $mode, int $options, ?string &$
/**
* Read from stream.
*
* @param int $count
* @param int $count
* @psalm-param positive-int $count
*
* @return string
* @noinspection PhpUnused
Expand Down Expand Up @@ -454,9 +469,9 @@ public function stream_seek(int $offset, int $whence = SEEK_SET): bool
/**
* Change stream options.
*
* @param int $option
* @param int $arg1
* @param int $arg2
* @param int $option
* @param int $arg1
* @param int|null $arg2
*
* @return bool|int
* @noinspection PhpUnused
Expand All @@ -469,11 +484,14 @@ public function stream_set_option(int $option, int $arg1, ?int $arg2)
switch ($option) {
case STREAM_OPTION_BLOCKING:
if (is_resource($this->resource)) {
$r = stream_set_blocking($this->resource, $arg1 ? true : false);
$r = stream_set_blocking($this->resource, (bool)$arg1);
}
break;

case STREAM_OPTION_READ_TIMEOUT:
if (is_null($arg2)) {
throw new InvalidArgumentException('Parameter #3 expects int.');
}
if (is_resource($this->resource)) {
$r = stream_set_timeout($this->resource, $arg1, $arg2);
}
Expand Down Expand Up @@ -550,7 +568,8 @@ public function stream_tell(): int
/**
* Truncate stream.
*
* @param int $new_size
* @param int $new_size
* @psalm-param positive-int $new_size
*
* @return bool
* @noinspection PhpUnused
Expand Down Expand Up @@ -616,7 +635,7 @@ public function unlink(string $path): bool
* Retrieve information about a file.
*
* @param string $path
* @param int $flags
* @param int $flags
*
* @return array<int|string, int>|false
* @noinspection PhpUnused
Expand Down

0 comments on commit 43f71bd

Please sign in to comment.