Skip to content

Commit

Permalink
:octocat: switch to phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed Aug 4, 2024
1 parent da3ecc7 commit 77d1d76
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 104 deletions.
40 changes: 21 additions & 19 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
/.build export-ignore
/.config export-ignore
/.github export-ignore
/.idea export-ignore
/.phan export-ignore
/.phpdoc export-ignore
/docs export-ignore
/examples export-ignore
/public export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.readthedocs.yml export-ignore
/composer.lock export-ignore
/phpcs.xml.dist export-ignore
/phpdoc.xml.dist export-ignore
/phpmd.xml.dist export-ignore
/phpunit.xml.dist export-ignore
/.build export-ignore
/.config export-ignore
/.github export-ignore
/.idea export-ignore
/.phan export-ignore
/.phpdoc export-ignore
/docs export-ignore
/examples export-ignore
/public export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.readthedocs.yml export-ignore
/composer.lock export-ignore
/phpcs.xml.dist export-ignore
/phpdoc.xml.dist export-ignore
/phpmd.xml.dist export-ignore
/phpunit.xml.dist export-ignore
/phpstan.dist.neon export-ignore
/phpstan-baseline.neon export-ignore

*.php diff=php
10 changes: 3 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ jobs:
- "8.2"
- "8.3"

env:
PHAN_ALLOW_XDEBUG: 0
PHAN_DISABLE_XDEBUG_WARN: 1

steps:
- name: "Checkout"
uses: actions/checkout@v4
Expand All @@ -50,7 +46,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: ast, ${{ env.PHP_EXTENSIONS }}
extensions: ${{ env.PHP_EXTENSIONS }}
ini-values: ${{ env.PHP_INI_VALUES }}
coverage: none

Expand All @@ -60,8 +56,8 @@ jobs:
- name: "Install dependencies with composer"
uses: ramsey/composer-install@v3

- name: "Run phan"
run: php vendor/bin/phan --target-php-version=${{ matrix.php-version }}
- name: "Run PHPStan"
run: php vendor/bin/phpstan

- name: "Run PHP_CodeSniffer"
run: php vendor/bin/phpcs
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ phpcs.xml
phpdoc.xml
phpmd.xml
phpunit.xml
phpstan.neon
63 changes: 0 additions & 63 deletions .phan/config.php

This file was deleted.

8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"ext-simplexml": "*",
"chillerlan/phpunit-http": "^1.0",
"http-interop/http-factory-tests": "^2.1",
"phan/phan": "^5.4",
"phpstan/phpstan": "^1.11",
"phpstan/phpstan-deprecation-rules": "^1.2",
"phpunit/phpunit": "^10.5",
"phpmd/phpmd": "^2.15",
"slevomat/coding-standard": "^8.15",
Expand All @@ -70,8 +71,9 @@
},
"scripts": {
"phpcs": "@php vendor/bin/phpcs",
"phpunit": "@php vendor/bin/phpunit",
"phan": "@php vendor/bin/phan"
"phpstan": "@php vendor/bin/phpstan",
"phpstan-baseline": "@php vendor/bin/phpstan --generate-baseline",
"phpunit": "@php vendor/bin/phpunit"
},
"config": {
"lock": false,
Expand Down
71 changes: 71 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
parameters:
ignoreErrors:
-
message: "#^Property chillerlan\\\\HTTP\\\\Psr7\\\\DummyStream\\:\\:\\$override \\(array\\<string, Closure\\>\\) does not accept non\\-empty\\-array\\<int\\|string, Closure\\>\\.$#"
count: 1
path: src/DummyStream.php

-
message: "#^Property chillerlan\\\\HTTP\\\\Psr7\\\\ServerRequest\\:\\:\\$uploadedFiles \\(array\\{tmp_name\\: array\\<string\\>, size\\: array\\<int\\>, error\\: array\\<int\\>, name\\: array\\<string\\>, type\\: array\\<string\\>\\}\\) does not accept default value of type array\\{\\}\\.$#"
count: 1
path: src/ServerRequest.php

-
message: "#^Parameter \\#1 \\$content of method Psr\\\\Http\\\\Message\\\\StreamFactoryInterface\\:\\:createStream\\(\\) expects string, string\\|null given\\.$#"
count: 1
path: src/UploadedFile.php

-
message: "#^Parameter \\#1 \\$filename of function is_file expects string, string\\|null given\\.$#"
count: 1
path: src/UploadedFile.php

-
message: "#^Parameter \\#1 \\$filename of method Psr\\\\Http\\\\Message\\\\StreamFactoryInterface\\:\\:createStreamFromFile\\(\\) expects string, string\\|null given\\.$#"
count: 1
path: src/UploadedFile.php

-
message: "#^Match expression does not handle remaining value\\: string$#"
count: 1
path: src/Uri.php

-
message: "#^Parameter \\#1 \\$host of method chillerlan\\\\HTTP\\\\Psr7\\\\Uri\\:\\:filterHost\\(\\) expects string, int\\|string given\\.$#"
count: 1
path: src/Uri.php

-
message: "#^Parameter \\#1 \\$parts of method chillerlan\\\\HTTP\\\\Psr7\\\\Uri\\:\\:parseUriParts\\(\\) expects array\\{scheme\\?\\: string, host\\?\\: string, port\\?\\: int\\|string, user\\?\\: string, pass\\?\\: string, path\\?\\: string, query\\?\\: string, fragment\\?\\: string\\}, array\\{port\\: int\\|null\\} given\\.$#"
count: 1
path: src/Uri.php

-
message: "#^Parameter \\#1 \\$parts of method chillerlan\\\\HTTP\\\\Psr7\\\\Uri\\:\\:parseUriParts\\(\\) expects array\\{scheme\\?\\: string, host\\?\\: string, port\\?\\: int\\|string, user\\?\\: string, pass\\?\\: string, path\\?\\: string, query\\?\\: string, fragment\\?\\: string\\}, array\\{scheme\\?\\: string, host\\?\\: int\\|string, port\\?\\: int\\|string, user\\?\\: string, pass\\?\\: string, path\\?\\: string, query\\?\\: string, fragment\\?\\: string\\} given\\.$#"
count: 1
path: src/Uri.php

-
message: "#^Parameter \\#1 \\$path of method chillerlan\\\\HTTP\\\\Psr7\\\\Uri\\:\\:filterPath\\(\\) expects string, int\\|string given\\.$#"
count: 1
path: src/Uri.php

-
message: "#^Parameter \\#1 \\$port of method chillerlan\\\\HTTP\\\\Psr7\\\\Uri\\:\\:filterPort\\(\\) expects int\\|null, int\\|string given\\.$#"
count: 1
path: src/Uri.php

-
message: "#^Parameter \\#1 \\$queryOrFragment of method chillerlan\\\\HTTP\\\\Psr7\\\\Uri\\:\\:filterQueryOrFragment\\(\\) expects string, int\\|string given\\.$#"
count: 1
path: src/Uri.php

-
message: "#^Parameter \\#1 \\$scheme of method chillerlan\\\\HTTP\\\\Psr7\\\\Uri\\:\\:filterScheme\\(\\) expects string, int\\|string given\\.$#"
count: 1
path: src/Uri.php

-
message: "#^Parameter \\#1 \\$userOrPass of method chillerlan\\\\HTTP\\\\Psr7\\\\Uri\\:\\:filterUserInfo\\(\\) expects string, int\\|string given\\.$#"
count: 1
path: src/Uri.php
17 changes: 17 additions & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# https://phpstan.org/config-reference

parameters:
level: 8
tmpDir: .build/phpstan-cache
paths:
# - examples
- src
# - tests

treatPhpDocTypesAsCertain: false


includes:
- phpstan-baseline.neon
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
2 changes: 2 additions & 0 deletions src/DummyStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class DummyStream implements StreamInterface{

/**
* DummyStream constructor
*
* @param array<string, \Closure>|null $methods
*/
public function __construct(StreamInterface|null $stream = null, array|null $methods = null){

Expand Down
5 changes: 4 additions & 1 deletion src/HTTPFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public function createUri(string $uri = ''):UriInterface{
return new Uri($uri);
}

/**
* @param array<int|string, mixed> $serverParams
*/
public function createServerRequest(string $method, $uri, array $serverParams = []):ServerRequestInterface{ // phpcs:ignore
return new ServerRequest($method, $uri, $serverParams);
}
Expand Down Expand Up @@ -118,7 +121,7 @@ public static function createStreamFromSource(mixed $source = null):StreamInterf

if($type === 'resource'){
// avoid using php://input and copy over the contents to a new stream
if((stream_get_meta_data($source)['uri'] ?? '') === 'php://input'){
if(stream_get_meta_data($source)['uri'] === 'php://input'){

Check failure on line 124 in src/HTTPFactory.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (8.1)

Offset 'uri' might not exist on array{timed_out: bool, blocked: bool, eof: bool, unread_bytes: int, stream_type: string, wrapper_type: string, wrapper_data: mixed, mode: string, ...}.

Check failure on line 124 in src/HTTPFactory.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis (8.2)

Offset 'uri' might not exist on array{timed_out: bool, blocked: bool, eof: bool, unread_bytes: int, stream_type: string, wrapper_type: string, wrapper_data: mixed, mode: string, ...}.
$stream = StreamUtil::tryFopen('php://temp', 'r+');

stream_copy_to_stream($source, $stream);
Expand Down
5 changes: 5 additions & 0 deletions src/MultipartStreamBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function __construct(StreamFactoryInterface $streamFactory){
* Returns the stream content (make sure to save the boundary before!)
*/
public function __toString():string{
/** @phpstan-ignore-next-line build() always returns a StreamInterface here */
return $this->build()->getContents();
}

Expand Down Expand Up @@ -94,6 +95,8 @@ protected function getRandomBoundary():string{

/**
* Adds a message with the given content
*
* @phpstan-param array<string, string>|null $headers
*/
public function addString(
string $content,
Expand All @@ -107,6 +110,8 @@ public function addString(

/**
* Adds a StreamInterface
*
* @phpstan-param array<string, string>|null $headers
*/
public function addStream(
StreamInterface $stream,
Expand Down
Loading

0 comments on commit 77d1d76

Please sign in to comment.