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 8a64441 commit 42fd089
Show file tree
Hide file tree
Showing 60 changed files with 385 additions and 306 deletions.
39 changes: 21 additions & 18 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,20 +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
/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 @@ -40,10 +40,6 @@ jobs:
- "8.3"
# - "8.4"

env:
PHAN_ALLOW_XDEBUG: 0
PHAN_DISABLE_XDEBUG_WARN: 1

steps:
- name: "Checkout"
uses: actions/checkout@v4
Expand All @@ -52,15 +48,15 @@ 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

- 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 @@ -21,3 +21,4 @@ phpcs.xml
phpdoc.xml
phpmd.xml
phpunit.xml
phpstan.neon
57 changes: 0 additions & 57 deletions .phan/config.php

This file was deleted.

18 changes: 10 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,20 @@
"php": "^8.1",
"ext-json": "*",
"ext-sodium": "*",
"chillerlan/php-http-message-utils": "^2.2.1",
"chillerlan/php-settings-container": "^3.2",
"chillerlan/php-http-message-utils": "^2.2.2",
"chillerlan/php-settings-container": "^3.2.1",
"psr/http-client": "^1.0",
"psr/http-message": "^1.1 || ^2.0",
"psr/log": "^1.1 || ^2.0 || ^3.0"
},
"require-dev": {
"chillerlan/php-dotenv": "^3.0",
"chillerlan/phpunit-http": "^1.0",
"guzzlehttp/guzzle": "^7.8",
"monolog/monolog": "^3.6",
"phan/phan": "^5.4",
"guzzlehttp/guzzle": "^7.9",
"monolog/monolog": "^3.7",
"phpmd/phpmd": "^2.15",
"phpstan/phpstan": "^1.11",
"phpstan/phpstan-deprecation-rules": "^1.2",
"phpunit/phpunit": "^10.5",
"slevomat/coding-standard": "^8.15",
"squizlabs/php_codesniffer": "^3.10"
Expand All @@ -56,17 +57,18 @@
},
"autoload": {
"psr-4": {
"chillerlan\\OAuth\\": "src/"
"chillerlan\\OAuth\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"chillerlan\\OAuthTest\\": "tests/"
"chillerlan\\OAuthTest\\": "tests"
}
},
"scripts": {
"phan": "@php vendor/bin/phan",
"phpcs": "@php vendor/bin/phpcs",
"phpstan": "@php vendor/bin/phpstan",
"phpstan-baseline": "@php vendor/bin/phpstan --generate-baseline",
"phpunit": "@php vendor/bin/phpunit"
},
"config": {
Expand Down
137 changes: 137 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#2 \\$array of function implode expects array\\|null, array\\<string\\>\\|string given\\.$#"
count: 2
path: src/Core/OAuth1Provider.php

-
message: "#^Parameter \\#1 \\$separator of function explode expects non\\-empty\\-string, string given\\.$#"
count: 1
path: src/Core/OAuth2Provider.php

-
message: "#^Method chillerlan\\\\OAuth\\\\Core\\\\OAuthProvider\\:\\:cleanBodyParams\\(\\) should return array\\<string, string\\> but returns array\\<int\\|string, bool\\|float\\|int\\|string\\|null\\>\\.$#"
count: 1
path: src/Core/OAuthProvider.php

-
message: "#^Method chillerlan\\\\OAuth\\\\Core\\\\OAuthProvider\\:\\:cleanQueryParams\\(\\) should return array\\<string, string\\> but returns array\\<int\\|string, bool\\|float\\|int\\|string\\|null\\>\\.$#"
count: 1
path: src/Core/OAuthProvider.php

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

-
message: "#^Parameter \\#1 \\$length of function random_bytes expects int\\<1, max\\>, int given\\.$#"
count: 1
path: src/Core/OAuthProvider.php

-
message: "#^Parameter \\#1 \\$objectOrClass of class ReflectionClass constructor expects class\\-string\\<T of object\\>\\|T of object, string given\\.$#"
count: 1
path: src/Core/Utilities.php

-
message: "#^Method chillerlan\\\\OAuth\\\\OAuthProviderFactory\\:\\:getProvider\\(\\) should return chillerlan\\\\OAuth\\\\Core\\\\OAuthInterface but returns object\\.$#"
count: 1
path: src/OAuthProviderFactory.php

-
message: "#^Access to an undefined property object\\:\\:\\$name\\.$#"
count: 1
path: src/Providers/GuildWars2.php

-
message: "#^Access to an undefined property object\\:\\:\\$permissions\\.$#"
count: 1
path: src/Providers/GuildWars2.php

-
message: "#^Method chillerlan\\\\OAuth\\\\Providers\\\\LastFM\\:\\:parseTrack\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Providers/LastFM.php

-
message: "#^Method chillerlan\\\\OAuth\\\\Providers\\\\LastFM\\:\\:scrobble\\(\\) has parameter \\$tracks with no value type specified in iterable type array\\.$#"
count: 1
path: src/Providers/LastFM.php

-
message: "#^Method chillerlan\\\\OAuth\\\\Providers\\\\LastFM\\:\\:scrobble\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Providers/LastFM.php

-
message: "#^Method chillerlan\\\\OAuth\\\\Providers\\\\LastFM\\:\\:sendScrobbles\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Providers/LastFM.php

-
message: "#^Parameter \\#1 \\$body of method chillerlan\\\\OAuth\\\\Providers\\\\LastFM\\:\\:sendScrobbles\\(\\) expects array\\<string, string\\>, array\\<string, bool\\|float\\|int\\|string\\> given\\.$#"
count: 1
path: src/Providers/LastFM.php

-
message: "#^Property chillerlan\\\\OAuth\\\\Core\\\\AccessToken\\:\\:\\$expires \\(int\\) does not accept DateInterval\\|DateTime\\|int\\|null\\.$#"
count: 1
path: tests/Core/AccessTokenTest.php

-
message: "#^Call to method chillerlan\\\\OAuth\\\\Core\\\\AuthenticatedUser\\:\\:fromIterable\\(\\) on a separate line has no effect\\.$#"
count: 1
path: tests/Core/AuthenticatedUserTest.php

-
message: "#^Parameter \\#1 \\$objectOrClass of class ReflectionClass constructor expects class\\-string\\<T of object\\>\\|T of object, string given\\.$#"
count: 2
path: tests/Core/UtilitiesTest.php

-
message: "#^Parameter \\#2 \\$string of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertMatchesRegularExpression\\(\\) expects string, int\\|string given\\.$#"
count: 1
path: tests/Providers/Live/AmazonAPITest.php

-
message: "#^Access to an undefined property chillerlan\\\\DotEnv\\\\DotEnv\\:\\:\\$GW2_TOKEN\\.$#"
count: 1
path: tests/Providers/Live/GuildWars2APITest.php

-
message: "#^Access to an undefined property chillerlan\\\\DotEnv\\\\DotEnv\\:\\:\\$GW2_TOKEN_NAME\\.$#"
count: 1
path: tests/Providers/Live/GuildWars2APITest.php

-
message: "#^Dead catch \\- chillerlan\\\\OAuth\\\\Providers\\\\ProviderException is never thrown in the try block\\.$#"
count: 1
path: tests/Providers/Live/MusicBrainzAPITest.php

-
message: """
#^Fetching class constant class of deprecated class chillerlan\\\\OAuth\\\\Providers\\\\OpenStreetmap\\:
https\\://github\\.com/openstreetmap/operations/issues/867$#
"""
count: 1
path: tests/Providers/Live/OpenStreetmapAPITest.php

-
message: "#^Parameter \\#1 \\$content of method Psr\\\\Http\\\\Message\\\\StreamFactoryInterface\\:\\:createStream\\(\\) expects string, string\\|false given\\.$#"
count: 2
path: tests/Providers/Unit/OAuth2ProviderUnitTestAbstract.php

-
message: "#^Parameter \\#1 \\$expected of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) expects class\\-string\\<object\\>, string given\\.$#"
count: 1
path: tests/Providers/Unit/OAuthProviderUnitTestAbstract.php

-
message: """
#^Fetching class constant class of deprecated class chillerlan\\\\OAuth\\\\Providers\\\\OpenStreetmap\\:
https\\://github\\.com/openstreetmap/operations/issues/867$#
"""
count: 1
path: tests/Providers/Unit/OpenStreetmapTest.php
18 changes: 18 additions & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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
- vendor/chillerlan/php-settings-container/rules-magic-access.neon
8 changes: 8 additions & 0 deletions src/Core/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
*
* @link https://datatracker.ietf.org/doc/html/rfc5849#section-2.3
* @link https://datatracker.ietf.org/doc/html/rfc6749#section-1.4
*
* @property string|null $accessToken
* @property string|null $accessTokenSecret
* @property string|null $refreshToken
* @property int $expires
* @property string[] $scopes
* @property array<string, mixed> $extraParams
* @property string|null $provider
*/
final class AccessToken extends SettingsContainerAbstract{

Expand Down
8 changes: 8 additions & 0 deletions src/Core/AuthenticatedUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
* A simple read-only container for user data responses
*
* @see \chillerlan\OAuth\Core\UserInfo::me()
*
* @property string|null $handle
* @property string|null $displayName
* @property string|null $email
* @property string|int|null $id
* @property string|null $avatar
* @property string|null $url
* @property array<string, mixed> $data
*/
final class AuthenticatedUser extends SettingsContainerAbstract{

Expand Down
Loading

0 comments on commit 42fd089

Please sign in to comment.