Skip to content

Commit 42fd089

Browse files
committed
:octocat: switch to phpstan
1 parent 8a64441 commit 42fd089

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+385
-306
lines changed

.gitattributes

+21-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +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-
/phpcs.xml.dist export-ignore
16-
/phpdoc.xml.dist export-ignore
17-
/phpmd.xml.dist export-ignore
18-
/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
1922

2023
*.php diff=php

.github/workflows/ci.yml

+3-7
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ jobs:
4040
- "8.3"
4141
# - "8.4"
4242

43-
env:
44-
PHAN_ALLOW_XDEBUG: 0
45-
PHAN_DISABLE_XDEBUG_WARN: 1
46-
4743
steps:
4844
- name: "Checkout"
4945
uses: actions/checkout@v4
@@ -52,15 +48,15 @@ jobs:
5248
uses: shivammathur/setup-php@v2
5349
with:
5450
php-version: ${{ matrix.php-version }}
55-
extensions: ast, ${{ env.PHP_EXTENSIONS }}
51+
extensions: ${{ env.PHP_EXTENSIONS }}
5652
ini-values: ${{ env.PHP_INI_VALUES }}
5753
coverage: none
5854

5955
- name: "Install dependencies with composer"
6056
uses: ramsey/composer-install@v3
6157

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

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

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ phpcs.xml
2121
phpdoc.xml
2222
phpmd.xml
2323
phpunit.xml
24+
phpstan.neon

.phan/config.php

-57
This file was deleted.

composer.json

+10-8
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,20 @@
3434
"php": "^8.1",
3535
"ext-json": "*",
3636
"ext-sodium": "*",
37-
"chillerlan/php-http-message-utils": "^2.2.1",
38-
"chillerlan/php-settings-container": "^3.2",
37+
"chillerlan/php-http-message-utils": "^2.2.2",
38+
"chillerlan/php-settings-container": "^3.2.1",
3939
"psr/http-client": "^1.0",
4040
"psr/http-message": "^1.1 || ^2.0",
4141
"psr/log": "^1.1 || ^2.0 || ^3.0"
4242
},
4343
"require-dev": {
4444
"chillerlan/php-dotenv": "^3.0",
4545
"chillerlan/phpunit-http": "^1.0",
46-
"guzzlehttp/guzzle": "^7.8",
47-
"monolog/monolog": "^3.6",
48-
"phan/phan": "^5.4",
46+
"guzzlehttp/guzzle": "^7.9",
47+
"monolog/monolog": "^3.7",
4948
"phpmd/phpmd": "^2.15",
49+
"phpstan/phpstan": "^1.11",
50+
"phpstan/phpstan-deprecation-rules": "^1.2",
5051
"phpunit/phpunit": "^10.5",
5152
"slevomat/coding-standard": "^8.15",
5253
"squizlabs/php_codesniffer": "^3.10"
@@ -56,17 +57,18 @@
5657
},
5758
"autoload": {
5859
"psr-4": {
59-
"chillerlan\\OAuth\\": "src/"
60+
"chillerlan\\OAuth\\": "src"
6061
}
6162
},
6263
"autoload-dev": {
6364
"psr-4": {
64-
"chillerlan\\OAuthTest\\": "tests/"
65+
"chillerlan\\OAuthTest\\": "tests"
6566
}
6667
},
6768
"scripts": {
68-
"phan": "@php vendor/bin/phan",
6969
"phpcs": "@php vendor/bin/phpcs",
70+
"phpstan": "@php vendor/bin/phpstan",
71+
"phpstan-baseline": "@php vendor/bin/phpstan --generate-baseline",
7072
"phpunit": "@php vendor/bin/phpunit"
7173
},
7274
"config": {

phpstan-baseline.neon

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Parameter \\#2 \\$array of function implode expects array\\|null, array\\<string\\>\\|string given\\.$#"
5+
count: 2
6+
path: src/Core/OAuth1Provider.php
7+
8+
-
9+
message: "#^Parameter \\#1 \\$separator of function explode expects non\\-empty\\-string, string given\\.$#"
10+
count: 1
11+
path: src/Core/OAuth2Provider.php
12+
13+
-
14+
message: "#^Method chillerlan\\\\OAuth\\\\Core\\\\OAuthProvider\\:\\:cleanBodyParams\\(\\) should return array\\<string, string\\> but returns array\\<int\\|string, bool\\|float\\|int\\|string\\|null\\>\\.$#"
15+
count: 1
16+
path: src/Core/OAuthProvider.php
17+
18+
-
19+
message: "#^Method chillerlan\\\\OAuth\\\\Core\\\\OAuthProvider\\:\\:cleanQueryParams\\(\\) should return array\\<string, string\\> but returns array\\<int\\|string, bool\\|float\\|int\\|string\\|null\\>\\.$#"
20+
count: 1
21+
path: src/Core/OAuthProvider.php
22+
23+
-
24+
message: "#^Parameter \\#1 \\$content of method Psr\\\\Http\\\\Message\\\\StreamFactoryInterface\\:\\:createStream\\(\\) expects string, string\\|false given\\.$#"
25+
count: 1
26+
path: src/Core/OAuthProvider.php
27+
28+
-
29+
message: "#^Parameter \\#1 \\$length of function random_bytes expects int\\<1, max\\>, int given\\.$#"
30+
count: 1
31+
path: src/Core/OAuthProvider.php
32+
33+
-
34+
message: "#^Parameter \\#1 \\$objectOrClass of class ReflectionClass constructor expects class\\-string\\<T of object\\>\\|T of object, string given\\.$#"
35+
count: 1
36+
path: src/Core/Utilities.php
37+
38+
-
39+
message: "#^Method chillerlan\\\\OAuth\\\\OAuthProviderFactory\\:\\:getProvider\\(\\) should return chillerlan\\\\OAuth\\\\Core\\\\OAuthInterface but returns object\\.$#"
40+
count: 1
41+
path: src/OAuthProviderFactory.php
42+
43+
-
44+
message: "#^Access to an undefined property object\\:\\:\\$name\\.$#"
45+
count: 1
46+
path: src/Providers/GuildWars2.php
47+
48+
-
49+
message: "#^Access to an undefined property object\\:\\:\\$permissions\\.$#"
50+
count: 1
51+
path: src/Providers/GuildWars2.php
52+
53+
-
54+
message: "#^Method chillerlan\\\\OAuth\\\\Providers\\\\LastFM\\:\\:parseTrack\\(\\) return type has no value type specified in iterable type array\\.$#"
55+
count: 1
56+
path: src/Providers/LastFM.php
57+
58+
-
59+
message: "#^Method chillerlan\\\\OAuth\\\\Providers\\\\LastFM\\:\\:scrobble\\(\\) has parameter \\$tracks with no value type specified in iterable type array\\.$#"
60+
count: 1
61+
path: src/Providers/LastFM.php
62+
63+
-
64+
message: "#^Method chillerlan\\\\OAuth\\\\Providers\\\\LastFM\\:\\:scrobble\\(\\) return type has no value type specified in iterable type array\\.$#"
65+
count: 1
66+
path: src/Providers/LastFM.php
67+
68+
-
69+
message: "#^Method chillerlan\\\\OAuth\\\\Providers\\\\LastFM\\:\\:sendScrobbles\\(\\) return type has no value type specified in iterable type array\\.$#"
70+
count: 1
71+
path: src/Providers/LastFM.php
72+
73+
-
74+
message: "#^Parameter \\#1 \\$body of method chillerlan\\\\OAuth\\\\Providers\\\\LastFM\\:\\:sendScrobbles\\(\\) expects array\\<string, string\\>, array\\<string, bool\\|float\\|int\\|string\\> given\\.$#"
75+
count: 1
76+
path: src/Providers/LastFM.php
77+
78+
-
79+
message: "#^Property chillerlan\\\\OAuth\\\\Core\\\\AccessToken\\:\\:\\$expires \\(int\\) does not accept DateInterval\\|DateTime\\|int\\|null\\.$#"
80+
count: 1
81+
path: tests/Core/AccessTokenTest.php
82+
83+
-
84+
message: "#^Call to method chillerlan\\\\OAuth\\\\Core\\\\AuthenticatedUser\\:\\:fromIterable\\(\\) on a separate line has no effect\\.$#"
85+
count: 1
86+
path: tests/Core/AuthenticatedUserTest.php
87+
88+
-
89+
message: "#^Parameter \\#1 \\$objectOrClass of class ReflectionClass constructor expects class\\-string\\<T of object\\>\\|T of object, string given\\.$#"
90+
count: 2
91+
path: tests/Core/UtilitiesTest.php
92+
93+
-
94+
message: "#^Parameter \\#2 \\$string of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertMatchesRegularExpression\\(\\) expects string, int\\|string given\\.$#"
95+
count: 1
96+
path: tests/Providers/Live/AmazonAPITest.php
97+
98+
-
99+
message: "#^Access to an undefined property chillerlan\\\\DotEnv\\\\DotEnv\\:\\:\\$GW2_TOKEN\\.$#"
100+
count: 1
101+
path: tests/Providers/Live/GuildWars2APITest.php
102+
103+
-
104+
message: "#^Access to an undefined property chillerlan\\\\DotEnv\\\\DotEnv\\:\\:\\$GW2_TOKEN_NAME\\.$#"
105+
count: 1
106+
path: tests/Providers/Live/GuildWars2APITest.php
107+
108+
-
109+
message: "#^Dead catch \\- chillerlan\\\\OAuth\\\\Providers\\\\ProviderException is never thrown in the try block\\.$#"
110+
count: 1
111+
path: tests/Providers/Live/MusicBrainzAPITest.php
112+
113+
-
114+
message: """
115+
#^Fetching class constant class of deprecated class chillerlan\\\\OAuth\\\\Providers\\\\OpenStreetmap\\:
116+
https\\://github\\.com/openstreetmap/operations/issues/867$#
117+
"""
118+
count: 1
119+
path: tests/Providers/Live/OpenStreetmapAPITest.php
120+
121+
-
122+
message: "#^Parameter \\#1 \\$content of method Psr\\\\Http\\\\Message\\\\StreamFactoryInterface\\:\\:createStream\\(\\) expects string, string\\|false given\\.$#"
123+
count: 2
124+
path: tests/Providers/Unit/OAuth2ProviderUnitTestAbstract.php
125+
126+
-
127+
message: "#^Parameter \\#1 \\$expected of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) expects class\\-string\\<object\\>, string given\\.$#"
128+
count: 1
129+
path: tests/Providers/Unit/OAuthProviderUnitTestAbstract.php
130+
131+
-
132+
message: """
133+
#^Fetching class constant class of deprecated class chillerlan\\\\OAuth\\\\Providers\\\\OpenStreetmap\\:
134+
https\\://github\\.com/openstreetmap/operations/issues/867$#
135+
"""
136+
count: 1
137+
path: tests/Providers/Unit/OpenStreetmapTest.php

phpstan.dist.neon

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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
18+
- vendor/chillerlan/php-settings-container/rules-magic-access.neon

src/Core/AccessToken.php

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
*
2323
* @link https://datatracker.ietf.org/doc/html/rfc5849#section-2.3
2424
* @link https://datatracker.ietf.org/doc/html/rfc6749#section-1.4
25+
*
26+
* @property string|null $accessToken
27+
* @property string|null $accessTokenSecret
28+
* @property string|null $refreshToken
29+
* @property int $expires
30+
* @property string[] $scopes
31+
* @property array<string, mixed> $extraParams
32+
* @property string|null $provider
2533
*/
2634
final class AccessToken extends SettingsContainerAbstract{
2735

src/Core/AuthenticatedUser.php

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
* A simple read-only container for user data responses
2121
*
2222
* @see \chillerlan\OAuth\Core\UserInfo::me()
23+
*
24+
* @property string|null $handle
25+
* @property string|null $displayName
26+
* @property string|null $email
27+
* @property string|int|null $id
28+
* @property string|null $avatar
29+
* @property string|null $url
30+
* @property array<string, mixed> $data
2331
*/
2432
final class AuthenticatedUser extends SettingsContainerAbstract{
2533

0 commit comments

Comments
 (0)