File tree 15 files changed +113
-87
lines changed
15 files changed +113
-87
lines changed Original file line number Diff line number Diff line change 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
16
19
17
20
* .php diff =php
Original file line number Diff line number Diff line change 44
44
uses : shivammathur/setup-php@v2
45
45
with :
46
46
php-version : ${{ matrix.php-version }}
47
- extensions : ast, ${{ env.PHP_EXTENSIONS }}
47
+ extensions : ${{ env.PHP_EXTENSIONS }}
48
48
ini-values : ${{ env.PHP_INI_VALUES }}
49
49
coverage : none
50
50
54
54
- name : " Install dependencies with composer"
55
55
uses : ramsey/composer-install@v3
56
56
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
59
59
60
60
61
61
tests :
Original file line number Diff line number Diff line change @@ -6,4 +6,5 @@ phpcs.xml
6
6
phpdoc.xml
7
7
phpmd.xml
8
8
phpunit.xml
9
+ phpstan.neon
9
10
* .phpunit.result.cache
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 32
32
"prefer-stable" : true ,
33
33
"require" : {
34
34
"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 " ,
36
36
"paragonie/constant_time_encoding" : " ^2.6"
37
37
},
38
38
"require-dev" : {
39
39
"ext-curl" : " *" ,
40
40
"ext-json" : " *" ,
41
41
"ext-sodium" : " *" ,
42
- "phan/phan" : " ^5.4" ,
43
42
"phpmd/phpmd" : " ^2.15" ,
43
+ "phpstan/phpstan" : " ^1.11" ,
44
+ "phpstan/phpstan-deprecation-rules" : " ^1.2" ,
44
45
"phpunit/phpunit" : " ^9.6" ,
45
- "squizlabs/php_codesniffer" : " ^3.9 "
46
+ "squizlabs/php_codesniffer" : " ^3.10 "
46
47
},
47
48
"suggest" : {
48
49
"chillerlan/php-qrcode" : " Create QR Codes for use with an authenticator app."
58
59
}
59
60
},
60
61
"scripts" : {
61
- "phan" : " @php vendor/bin/phan --allow-polyfill-parser" ,
62
62
"phpcs" : " @php vendor/bin/phpcs" ,
63
- "phpunit" : " @php vendor/bin/phpunit"
63
+ "phpunit" : " @php vendor/bin/phpunit" ,
64
+ "phpstan" : " @php vendor/bin/phpstan"
64
65
},
65
66
"config" : {
66
67
"lock" : false ,
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 8
8
>
9
9
<testsuites >
10
10
<testsuite name =" php-authenticator test suite" >
11
- <directory suffix = " .php " >./ tests</directory >
11
+ <directory > tests</directory >
12
12
</testsuite >
13
13
</testsuites >
14
14
<coverage processUncoveredFiles =" true" >
15
15
<include >
16
- <directory suffix =" .php" >./ src</directory >
16
+ <directory suffix =" .php" >src</directory >
17
17
</include >
18
18
<report >
19
19
<clover outputFile =" .build/coverage/clover.xml" />
Original file line number Diff line number Diff line change 17
17
use function strtolower ;
18
18
use function strtoupper ;
19
19
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
+ */
20
31
trait AuthenticatorOptionsTrait{
21
32
22
33
/**
Original file line number Diff line number Diff line change @@ -54,7 +54,12 @@ public function getHMAC(int $counter):string{
54
54
*/
55
55
public function getCode (string $ hmac ):int {
56
56
$ 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 );
58
63
// phpcs:ignore
59
64
return (($ data [$ b + 1 ] & 0x7F ) << 24 ) | ($ data [$ b + 2 ] << 16 ) | ($ data [$ b + 3 ] << 8 ) | $ data [$ b + 4 ];
60
65
}
Original file line number Diff line number Diff line change 22
22
use function curl_setopt_array ;
23
23
use function floor ;
24
24
use function intdiv ;
25
+ use function is_array ;
25
26
use function json_decode ;
26
27
use function sprintf ;
27
28
use function time ;
@@ -128,21 +129,26 @@ public function getServerTime():int{
128
129
129
130
$ ch = curl_init ($ this ::steamTimeURL);
130
131
132
+ // it's almost impossible to run into this, but hey, phpstan happy
133
+ if ($ ch === false ){
134
+ throw new RuntimeException ('curl_init error ' ); // @codeCoverageIgnore
135
+ }
136
+
131
137
curl_setopt_array ($ ch , $ options );
132
138
133
139
$ response = curl_exec ($ ch );
134
140
$ info = curl_getinfo ($ ch );
135
141
136
142
curl_close ($ ch );
137
143
138
- if ($ info ['http_code ' ] !== 200 ){
144
+ if ($ info ['http_code ' ] !== 200 || $ response === false ){
139
145
// I'm not going to investigate the error further as this shouldn't happen usually
140
146
throw new RuntimeException (sprintf ('Steam API request error: HTTP/%s ' , $ info ['http_code ' ])); // @codeCoverageIgnore
141
147
}
142
148
143
149
$ json = json_decode ($ response , true );
144
150
145
- if (empty ($ json ) || !isset ($ json ['response ' ]['server_time ' ])){
151
+ if (! is_array ($ json ) || !isset ($ json ['response ' ]['server_time ' ])){
146
152
throw new RuntimeException ('Unable to decode Steam API response ' ); // @codeCoverageIgnore
147
153
}
148
154
Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ public function testGetUri():void{
84
84
);
85
85
}
86
86
87
- public function testGetUriEmptyLabelException (){
87
+ public function testGetUriEmptyLabelException (): void {
88
88
$ this ->expectException (InvalidArgumentException::class);
89
89
$ this ->expectExceptionMessage ('$label and $issuer cannot be empty ' );
90
90
Original file line number Diff line number Diff line change 17
17
18
18
class Base32Test extends TestCase{
19
19
20
+ /**
21
+ * @phpstan-return array<int, array<int, string>>
22
+ */
20
23
public static function base32DataProvider ():array {
21
24
return [
22
25
['a ' , 'ME ' ],
Original file line number Diff line number Diff line change 22
22
*/
23
23
class Base64Test extends TestCase{
24
24
25
+ /**
26
+ * @phpstan-return array<int, array<int, string>>
27
+ */
25
28
public static function base64DataProvider ():array {
26
29
return [
27
30
['a ' , 'YQ== ' ],
Original file line number Diff line number Diff line change 22
22
*/
23
23
class HexTest extends TestCase{
24
24
25
+ /**
26
+ * @phpstan-return array<int, array<int, string>>
27
+ */
25
28
public static function hexDataProvider ():array {
26
29
return [
27
30
['a ' , '61 ' ],
You can’t perform that action at this time.
0 commit comments