Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add phpstan to CI #3

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand All @@ -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
2 changes: 1 addition & 1 deletion .mddoc.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<section title="Quorum Stream Functions">
<badge-poser type="version"/>
<badge-poser type="license"/>
<badge-github-action name="QuorumCollection/StreamFunctions" workflow="CI"/>
<badge-github-action name="QuorumCollection/StreamFunctions" workflow-file="ci.yml"/>
<text>Useful functions for manipulating PHP streams (resources).</text>
<text>The general structure of these are inspired by a [talk given by Rob Pike](https://www.youtube.com/watch?v=HxaD_trXwRE).</text>

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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

Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 6
paths:
- src
- test
6 changes: 3 additions & 3 deletions src/streams.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ 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 {
if( !is_resource($stream) ) {
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;
Expand Down
2 changes: 2 additions & 0 deletions test/StreamsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand All @@ -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);
}

Expand Down