Skip to content

Commit 488b114

Browse files
committed
✨ switch phan for phpstan (see chillerlan/php-qrcode#277)
(cherry picked from commit ee00916)
1 parent eb7e949 commit 488b114

File tree

15 files changed

+113
-87
lines changed

15 files changed

+113
-87
lines changed

.gitattributes

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
/.build export-ignore
2-
/.github export-ignore
3-
/.phan export-ignore
4-
/.phpdoc export-ignore
5-
/docs export-ignore
6-
/examples export-ignore
7-
/tests export-ignore
8-
/.editorconfig export-ignore
9-
/.gitattributes export-ignore
10-
/.gitignore export-ignore
11-
/.readthedocs.yml export-ignore
12-
/phpcs.xml.dist export-ignore
13-
/phpdoc.xml.dist export-ignore
14-
/phpmd.xml.dist export-ignore
15-
/phpunit.xml.dist export-ignore
1+
/.build export-ignore
2+
/.github export-ignore
3+
/.idea export-ignore
4+
/.phan export-ignore
5+
/.phpdoc export-ignore
6+
/docs export-ignore
7+
/examples export-ignore
8+
/tests export-ignore
9+
/.editorconfig export-ignore
10+
/.gitattributes export-ignore
11+
/.gitignore export-ignore
12+
/.readthedocs.yml export-ignore
13+
/phpcs.xml.dist export-ignore
14+
/phpdoc.xml.dist export-ignore
15+
/phpmd.xml.dist export-ignore
16+
/phpunit.xml.dist export-ignore
17+
/phpstan.dist.neon export-ignore
18+
/phpstan-baseline.neon export-ignore
1619

1720
*.php diff=php

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
uses: shivammathur/setup-php@v2
4545
with:
4646
php-version: ${{ matrix.php-version }}
47-
extensions: ast, ${{ env.PHP_EXTENSIONS }}
47+
extensions: ${{ env.PHP_EXTENSIONS }}
4848
ini-values: ${{ env.PHP_INI_VALUES }}
4949
coverage: none
5050

@@ -54,8 +54,8 @@ jobs:
5454
- name: "Install dependencies with composer"
5555
uses: ramsey/composer-install@v3
5656

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

6060

6161
tests:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ phpcs.xml
66
phpdoc.xml
77
phpmd.xml
88
phpunit.xml
9+
phpstan.neon
910
*.phpunit.result.cache

.phan/config.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,18 @@
3232
"prefer-stable": true,
3333
"require": {
3434
"php": "^7.4 || ^8.0",
35-
"chillerlan/php-settings-container": "^2.1.5 || ^3.2",
35+
"chillerlan/php-settings-container": "^2.1.6 || ^3.2.1",
3636
"paragonie/constant_time_encoding": "^2.6"
3737
},
3838
"require-dev": {
3939
"ext-curl": "*",
4040
"ext-json": "*",
4141
"ext-sodium": "*",
42-
"phan/phan": "^5.4",
4342
"phpmd/phpmd": "^2.15",
43+
"phpstan/phpstan": "^1.11",
44+
"phpstan/phpstan-deprecation-rules": "^1.2",
4445
"phpunit/phpunit": "^9.6",
45-
"squizlabs/php_codesniffer": "^3.9"
46+
"squizlabs/php_codesniffer": "^3.10"
4647
},
4748
"suggest": {
4849
"chillerlan/php-qrcode": "Create QR Codes for use with an authenticator app."
@@ -58,9 +59,9 @@
5859
}
5960
},
6061
"scripts": {
61-
"phan": "@php vendor/bin/phan --allow-polyfill-parser",
6262
"phpcs": "@php vendor/bin/phpcs",
63-
"phpunit": "@php vendor/bin/phpunit"
63+
"phpunit": "@php vendor/bin/phpunit",
64+
"phpstan": "@php vendor/bin/phpstan"
6465
},
6566
"config": {
6667
"lock": false,

phpstan-baseline.neon

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Cannot access offset 'server_time' on mixed\\.$#"
5+
count: 1
6+
path: src/Authenticators/SteamGuard.php
7+
8+
-
9+
message: "#^Cannot cast mixed to int\\.$#"
10+
count: 1
11+
path: src/Authenticators/SteamGuard.php
12+
13+
- # $response is always string here because CURLOPT_RETURNTRANSFER is set to true
14+
message: "#^Parameter \\#1 \\$json of function json_decode expects string, string\\|true given\\.$#"
15+
count: 1
16+
path: src/Authenticators/SteamGuard.php
17+
18+
- # the value given to getHMAC() is always int - this is most likely a false positive
19+
message: "#^Parameter \\#1 \\$counter of method chillerlan\\\\Authenticator\\\\Authenticators\\\\HOTP\\:\\:getHMAC\\(\\) expects int, float\\|int given\\.$#"
20+
count: 1
21+
path: src/Authenticators/TOTP.php
22+
23+
- # 32-bit system check
24+
message: "#^Call to function is_int\\(\\) with 59\\|1111111109\\|1111111111\\|1234567890\\|2000000000\\|20000000000 will always evaluate to true\\.$#"
25+
count: 1
26+
path: tests/Authenticators/SteamGuardTest.php
27+
28+
- # 32-bit system check
29+
message: "#^Call to function is_int\\(\\) with 59\\|1111111109\\|1111111111\\|1234567890\\|2000000000\\|20000000000 will always evaluate to true\\.$#"
30+
count: 1
31+
path: tests/Authenticators/TOTPTest.php

phpstan.dist.neon

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

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
>
99
<testsuites>
1010
<testsuite name="php-authenticator test suite">
11-
<directory suffix=".php">./tests</directory>
11+
<directory>tests</directory>
1212
</testsuite>
1313
</testsuites>
1414
<coverage processUncoveredFiles="true">
1515
<include>
16-
<directory suffix=".php">./src</directory>
16+
<directory suffix=".php">src</directory>
1717
</include>
1818
<report>
1919
<clover outputFile=".build/coverage/clover.xml"/>

src/AuthenticatorOptionsTrait.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@
1717
use function strtolower;
1818
use function strtoupper;
1919

20+
/**
21+
* @property int $digits
22+
* @property int $period
23+
* @property int $secret_length
24+
* @property string $algorithm
25+
* @property string $mode
26+
* @property int $adjacent
27+
* @property int $time_offset
28+
* @property bool $useLocalTime
29+
* @property bool $forceTimeRefresh
30+
*/
2031
trait AuthenticatorOptionsTrait{
2132

2233
/**

src/Authenticators/HOTP.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ public function getHMAC(int $counter):string{
5454
*/
5555
public function getCode(string $hmac):int{
5656
$data = unpack('C*', $hmac);
57-
$b = ($data[strlen($hmac)] & 0xF);
57+
58+
if($data === false){
59+
throw new RuntimeException('error while unpacking HMAC'); // @codeCoverageIgnore
60+
}
61+
62+
$b = ($data[strlen($hmac)] & 0xF);
5863
// phpcs:ignore
5964
return (($data[$b + 1] & 0x7F) << 24) | ($data[$b + 2] << 16) | ($data[$b + 3] << 8) | $data[$b + 4];
6065
}

0 commit comments

Comments
 (0)