Skip to content

Commit 77d1d76

Browse files
committed
:octocat: switch to phpstan
1 parent da3ecc7 commit 77d1d76

12 files changed

+177
-104
lines changed

.gitattributes

+21-19
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
/.build export-ignore
2-
/.config export-ignore
3-
/.github export-ignore
4-
/.idea export-ignore
5-
/.phan export-ignore
6-
/.phpdoc export-ignore
7-
/docs export-ignore
8-
/examples export-ignore
9-
/public export-ignore
10-
/tests export-ignore
11-
/.editorconfig export-ignore
12-
/.gitattributes export-ignore
13-
/.gitignore export-ignore
14-
/.readthedocs.yml export-ignore
15-
/composer.lock export-ignore
16-
/phpcs.xml.dist export-ignore
17-
/phpdoc.xml.dist export-ignore
18-
/phpmd.xml.dist export-ignore
19-
/phpunit.xml.dist export-ignore
1+
/.build export-ignore
2+
/.config export-ignore
3+
/.github export-ignore
4+
/.idea export-ignore
5+
/.phan export-ignore
6+
/.phpdoc export-ignore
7+
/docs export-ignore
8+
/examples export-ignore
9+
/public export-ignore
10+
/tests export-ignore
11+
/.editorconfig export-ignore
12+
/.gitattributes export-ignore
13+
/.gitignore export-ignore
14+
/.readthedocs.yml export-ignore
15+
/composer.lock export-ignore
16+
/phpcs.xml.dist export-ignore
17+
/phpdoc.xml.dist export-ignore
18+
/phpmd.xml.dist export-ignore
19+
/phpunit.xml.dist export-ignore
20+
/phpstan.dist.neon export-ignore
21+
/phpstan-baseline.neon export-ignore
2022

2123
*.php diff=php

.github/workflows/ci.yml

+3-7
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ jobs:
3838
- "8.2"
3939
- "8.3"
4040

41-
env:
42-
PHAN_ALLOW_XDEBUG: 0
43-
PHAN_DISABLE_XDEBUG_WARN: 1
44-
4541
steps:
4642
- name: "Checkout"
4743
uses: actions/checkout@v4
@@ -50,7 +46,7 @@ jobs:
5046
uses: shivammathur/setup-php@v2
5147
with:
5248
php-version: ${{ matrix.php-version }}
53-
extensions: ast, ${{ env.PHP_EXTENSIONS }}
49+
extensions: ${{ env.PHP_EXTENSIONS }}
5450
ini-values: ${{ env.PHP_INI_VALUES }}
5551
coverage: none
5652

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

63-
- name: "Run phan"
64-
run: php vendor/bin/phan --target-php-version=${{ matrix.php-version }}
59+
- name: "Run PHPStan"
60+
run: php vendor/bin/phpstan
6561

6662
- name: "Run PHP_CodeSniffer"
6763
run: php vendor/bin/phpcs

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ phpcs.xml
1818
phpdoc.xml
1919
phpmd.xml
2020
phpunit.xml
21+
phpstan.neon

.phan/config.php

-63
This file was deleted.

composer.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
"ext-simplexml": "*",
4848
"chillerlan/phpunit-http": "^1.0",
4949
"http-interop/http-factory-tests": "^2.1",
50-
"phan/phan": "^5.4",
50+
"phpstan/phpstan": "^1.11",
51+
"phpstan/phpstan-deprecation-rules": "^1.2",
5152
"phpunit/phpunit": "^10.5",
5253
"phpmd/phpmd": "^2.15",
5354
"slevomat/coding-standard": "^8.15",
@@ -70,8 +71,9 @@
7071
},
7172
"scripts": {
7273
"phpcs": "@php vendor/bin/phpcs",
73-
"phpunit": "@php vendor/bin/phpunit",
74-
"phan": "@php vendor/bin/phan"
74+
"phpstan": "@php vendor/bin/phpstan",
75+
"phpstan-baseline": "@php vendor/bin/phpstan --generate-baseline",
76+
"phpunit": "@php vendor/bin/phpunit"
7577
},
7678
"config": {
7779
"lock": false,

phpstan-baseline.neon

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Property chillerlan\\\\HTTP\\\\Psr7\\\\DummyStream\\:\\:\\$override \\(array\\<string, Closure\\>\\) does not accept non\\-empty\\-array\\<int\\|string, Closure\\>\\.$#"
5+
count: 1
6+
path: src/DummyStream.php
7+
8+
-
9+
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\\{\\}\\.$#"
10+
count: 1
11+
path: src/ServerRequest.php
12+
13+
-
14+
message: "#^Parameter \\#1 \\$content of method Psr\\\\Http\\\\Message\\\\StreamFactoryInterface\\:\\:createStream\\(\\) expects string, string\\|null given\\.$#"
15+
count: 1
16+
path: src/UploadedFile.php
17+
18+
-
19+
message: "#^Parameter \\#1 \\$filename of function is_file expects string, string\\|null given\\.$#"
20+
count: 1
21+
path: src/UploadedFile.php
22+
23+
-
24+
message: "#^Parameter \\#1 \\$filename of method Psr\\\\Http\\\\Message\\\\StreamFactoryInterface\\:\\:createStreamFromFile\\(\\) expects string, string\\|null given\\.$#"
25+
count: 1
26+
path: src/UploadedFile.php
27+
28+
-
29+
message: "#^Match expression does not handle remaining value\\: string$#"
30+
count: 1
31+
path: src/Uri.php
32+
33+
-
34+
message: "#^Parameter \\#1 \\$host of method chillerlan\\\\HTTP\\\\Psr7\\\\Uri\\:\\:filterHost\\(\\) expects string, int\\|string given\\.$#"
35+
count: 1
36+
path: src/Uri.php
37+
38+
-
39+
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\\.$#"
40+
count: 1
41+
path: src/Uri.php
42+
43+
-
44+
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\\.$#"
45+
count: 1
46+
path: src/Uri.php
47+
48+
-
49+
message: "#^Parameter \\#1 \\$path of method chillerlan\\\\HTTP\\\\Psr7\\\\Uri\\:\\:filterPath\\(\\) expects string, int\\|string given\\.$#"
50+
count: 1
51+
path: src/Uri.php
52+
53+
-
54+
message: "#^Parameter \\#1 \\$port of method chillerlan\\\\HTTP\\\\Psr7\\\\Uri\\:\\:filterPort\\(\\) expects int\\|null, int\\|string given\\.$#"
55+
count: 1
56+
path: src/Uri.php
57+
58+
-
59+
message: "#^Parameter \\#1 \\$queryOrFragment of method chillerlan\\\\HTTP\\\\Psr7\\\\Uri\\:\\:filterQueryOrFragment\\(\\) expects string, int\\|string given\\.$#"
60+
count: 1
61+
path: src/Uri.php
62+
63+
-
64+
message: "#^Parameter \\#1 \\$scheme of method chillerlan\\\\HTTP\\\\Psr7\\\\Uri\\:\\:filterScheme\\(\\) expects string, int\\|string given\\.$#"
65+
count: 1
66+
path: src/Uri.php
67+
68+
-
69+
message: "#^Parameter \\#1 \\$userOrPass of method chillerlan\\\\HTTP\\\\Psr7\\\\Uri\\:\\:filterUserInfo\\(\\) expects string, int\\|string given\\.$#"
70+
count: 1
71+
path: src/Uri.php

phpstan.dist.neon

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# https://phpstan.org/config-reference
2+
3+
parameters:
4+
level: 8
5+
tmpDir: .build/phpstan-cache
6+
paths:
7+
# - examples
8+
- src
9+
# - tests
10+
11+
treatPhpDocTypesAsCertain: false
12+
13+
14+
includes:
15+
- phpstan-baseline.neon
16+
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
17+
- vendor/phpstan/phpstan-deprecation-rules/rules.neon

src/DummyStream.php

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class DummyStream implements StreamInterface{
4545

4646
/**
4747
* DummyStream constructor
48+
*
49+
* @param array<string, \Closure>|null $methods
4850
*/
4951
public function __construct(StreamInterface|null $stream = null, array|null $methods = null){
5052

src/HTTPFactory.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public function createUri(string $uri = ''):UriInterface{
6464
return new Uri($uri);
6565
}
6666

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

119122
if($type === 'resource'){
120123
// avoid using php://input and copy over the contents to a new stream
121-
if((stream_get_meta_data($source)['uri'] ?? '') === 'php://input'){
124+
if(stream_get_meta_data($source)['uri'] === 'php://input'){
122125
$stream = StreamUtil::tryFopen('php://temp', 'r+');
123126

124127
stream_copy_to_stream($source, $stream);

src/MultipartStreamBuilder.php

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function __construct(StreamFactoryInterface $streamFactory){
4242
* Returns the stream content (make sure to save the boundary before!)
4343
*/
4444
public function __toString():string{
45+
/** @phpstan-ignore-next-line build() always returns a StreamInterface here */
4546
return $this->build()->getContents();
4647
}
4748

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

9596
/**
9697
* Adds a message with the given content
98+
*
99+
* @phpstan-param array<string, string>|null $headers
97100
*/
98101
public function addString(
99102
string $content,
@@ -107,6 +110,8 @@ public function addString(
107110

108111
/**
109112
* Adds a StreamInterface
113+
*
114+
* @phpstan-param array<string, string>|null $headers
110115
*/
111116
public function addStream(
112117
StreamInterface $stream,

0 commit comments

Comments
 (0)