diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ffeefcf..d17992b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] + php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] runs-on: ${{ matrix.operating-system }} @@ -28,4 +28,7 @@ jobs: run: composer install - name: Run tests - run: ./vendor/bin/phpunit + run: vendor/bin/phpunit + + - name: Run tests + run: vendor/bin/phpstan diff --git a/.mddoc.xml.dist b/.mddoc.xml.dist index c1171a4..0d7d212 100644 --- a/.mddoc.xml.dist +++ b/.mddoc.xml.dist @@ -3,7 +3,7 @@
- + Useful functions for manipulating PHP streams (resources). The general structure of these are inspired by a [talk given by Rob Pike](https://www.youtube.com/watch?v=HxaD_trXwRE). diff --git a/README.md b/README.md index 56ec578..bdb39ae 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Latest Stable Version](https://poser.pugx.org/quorum/stream-functions/version)](https://packagist.org/packages/quorum/stream-functions) [![License](https://poser.pugx.org/quorum/stream-functions/license)](https://packagist.org/packages/quorum/stream-functions) -[![CI](https://github.com/QuorumCollection/StreamFunctions/workflows/CI/badge.svg?)](https://github.com/QuorumCollection/StreamFunctions/actions?query=workflow%3ACI) +[![ci.yml](https://github.com/QuorumCollection/StreamFunctions/actions/workflows/ci.yml/badge.svg?)](https://github.com/QuorumCollection/StreamFunctions/actions/workflows/ci.yml) Useful functions for manipulating PHP streams (resources). @@ -11,7 +11,7 @@ The general structure of these are inspired by a [talk given by Rob Pike](https: ## Requirements -- **php**: ^7.1|^8.0 +- **php**: ^7.2|^8.0 ## Installing diff --git a/composer.json b/composer.json index 022badb..5f36eaf 100644 --- a/composer.json +++ b/composer.json @@ -15,14 +15,18 @@ } ], "require": { - "php": "^7.1|^8.0" + "php": "^7.2|^8.0" }, "require-dev": { + "phpstan/phpstan": "^1.10", "phpunit/phpunit": "~5|~9" }, "autoload": { "files": [ "src/streams.php" ] + }, + "config": { + "sort-packages": true } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..aeb0535 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,5 @@ +parameters: + level: 6 + paths: + - src + - test diff --git a/src/streams.php b/src/streams.php index 3b1b8b3..a4041be 100644 --- a/src/streams.php +++ b/src/streams.php @@ -36,8 +36,8 @@ function faccept( $stream, string ...$accept ) : ?string { * * The cursor is reset to its original position. * - * @param resource $stream The stream to peek, must be a seekable resource - * @param int $length Up to length number of bytes read. + * @param resource $stream The stream to peek, must be a seekable resource + * @param int $length Up to length number of bytes read. * @return string The peeked string of up to length bytes */ function fpeek( $stream, int $length = 1 ) : string { @@ -45,7 +45,7 @@ function fpeek( $stream, int $length = 1 ) : string { throw new \InvalidArgumentException('Stream must be a resource'); } - $buf = fread($stream, $length); + $buf = fread($stream, $length) ?: ''; fseek($stream, 0 - strlen($buf), SEEK_CUR); return $buf; diff --git a/test/StreamsTest.php b/test/StreamsTest.php index d50bb51..821d063 100644 --- a/test/StreamsTest.php +++ b/test/StreamsTest.php @@ -32,6 +32,7 @@ public function test_faccept_BOM() : void { public function test_faccept_exception() : void { $this->expectException(\InvalidArgumentException::class); + // @phpstan-ignore-next-line faccept(123, 'test'); } @@ -54,6 +55,7 @@ public function test_fpeek_empty() : void { public function test_fpeek_exception() : void { $this->expectException(\InvalidArgumentException::class); + // @phpstan-ignore-next-line fpeek(123, 123); }