From 44f2ba3f5b860fda321fb4ce5ab34bc22ed542b7 Mon Sep 17 00:00:00 2001 From: Jesse Donat Date: Tue, 31 Oct 2023 16:11:02 -0500 Subject: [PATCH 1/4] Set minimum to PHP 7.2 --- .github/workflows/ci.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ffeefcf..c888c95 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 }} diff --git a/composer.json b/composer.json index 022badb..73b97e8 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": "^7.1|^8.0" + "php": "^7.2|^8.0" }, "require-dev": { "phpunit/phpunit": "~5|~9" From 6ec782a3b10150fe73625c26ac52d156912b7e1d Mon Sep 17 00:00:00 2001 From: Jesse Donat Date: Tue, 31 Oct 2023 16:12:17 -0500 Subject: [PATCH 2/4] Include phpstan as a ci step --- .github/workflows/ci.yml | 5 ++++- composer.json | 4 ++++ phpstan.neon | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 phpstan.neon diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c888c95..d17992b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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/composer.json b/composer.json index 73b97e8..5f36eaf 100644 --- a/composer.json +++ b/composer.json @@ -18,11 +18,15 @@ "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 From 8811e5968fe56d2c8095aa72780a1b07778883a1 Mon Sep 17 00:00:00 2001 From: Jesse Donat Date: Tue, 31 Oct 2023 16:13:05 -0500 Subject: [PATCH 3/4] Apply phpstan fixes --- src/streams.php | 6 +++--- test/StreamsTest.php | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) 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); } From fabfabee5fdda0ff815fa2bbb22d50a6a3b3c6b8 Mon Sep 17 00:00:00 2001 From: Jesse Donat Date: Tue, 31 Oct 2023 16:14:36 -0500 Subject: [PATCH 4/4] Rebuild README --- .mddoc.xml.dist | 2 +- README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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