Skip to content

Commit ff3077c

Browse files
authored
Update codebase for newer PHPStan (#99)
Newer PHPStan complains more rather than less about some GMP stuff. They're false-positives, see linked issues referenced in code.
1 parent 971dbab commit ff3077c

File tree

4 files changed

+17
-34
lines changed

4 files changed

+17
-34
lines changed

examples/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,6 @@ function uuidv4(): string
109109
$bytes = random_bytes(16);
110110
$hex = bin2hex($bytes);
111111
$chunks = str_split($hex, 4);
112-
$chunks[3][0] = '4';
112+
$chunks[3] = '4' . substr($chunks[3], 1);
113113
return sprintf('%s%s-%s-%s-%s-%s%s%s', ...$chunks);
114114
}

phpstan-baseline.neon

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ parameters:
3737
path: examples/readmeRegisterStep1.php
3838

3939
-
40-
message: '#^Parameter \#1 \$bytes of static method Firehed\\WebAuthn\\BinaryString\:\:fromBytes\(\) expects array\<int\>, array\<mixed, mixed\> given\.$#'
40+
message: '#^Parameter \#1 \$bytes of static method Firehed\\WebAuthn\\BinaryString\:\:fromBytes\(\) expects array\<int\<0, 255\>\>, array\<mixed, mixed\> given\.$#'
4141
identifier: argument.type
42-
count: 8
42+
count: 7
43+
path: src/ArrayBufferResponseParser.php
44+
45+
-
46+
message: '#^Parameter \#1 \$bytes of static method Firehed\\WebAuthn\\BinaryString\:\:fromBytes\(\) expects array\<int\<0, 255\>\>, non\-empty\-array\<mixed, mixed\> given\.$#'
47+
identifier: argument.type
48+
count: 1
4349
path: src/ArrayBufferResponseParser.php
4450

4551
-
@@ -204,24 +210,6 @@ parameters:
204210
count: 1
205211
path: src/ChallengeLoaderInterface.php
206212

207-
-
208-
message: '#^Binary operation "\+" between \(array\|float\|int\) and GMP results in an error\.$#'
209-
identifier: binaryOp.invalid
210-
count: 1
211-
path: src/PublicKey/EllipticCurve.php
212-
213-
-
214-
message: '#^Binary operation "\+" between mixed and mixed results in an error\.$#'
215-
identifier: binaryOp.invalid
216-
count: 1
217-
path: src/PublicKey/EllipticCurve.php
218-
219-
-
220-
message: '#^Parameter \#1 \$num1 of function gmp_cmp expects GMP\|int\|string, mixed given\.$#'
221-
identifier: argument.type
222-
count: 1
223-
path: src/PublicKey/EllipticCurve.php
224-
225213
-
226214
message: '#^Parameter \#1 \$string of function strlen expects string, mixed given\.$#'
227215
identifier: argument.type
@@ -252,12 +240,6 @@ parameters:
252240
count: 2
253241
path: src/PublicKey/EllipticCurve.php
254242

255-
-
256-
message: '#^Parameter \#2 \$num2 of function gmp_cmp expects GMP\|int\|string, mixed given\.$#'
257-
identifier: argument.type
258-
count: 1
259-
path: src/PublicKey/EllipticCurve.php
260-
261243
-
262244
message: '#^Parameter \#1 \$value of static method Firehed\\WebAuthn\\COSE\\Algorithm\:\:from\(\) expects int\|string, mixed given\.$#'
263245
identifier: argument.type

src/BinaryString.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ public function toBase64Url(): string
5454
/**
5555
* Turns a list of 8-bit integers into a BinaryString
5656
*
57-
* @param int[] $bytes
57+
* @param int<0, 255>[] $bytes
5858
*/
5959
public static function fromBytes(array $bytes): BinaryString
6060
{
61-
return new BinaryString(implode('', array_map('chr', $bytes)));
61+
return new BinaryString(implode('', array_map(chr(...), $bytes)));
6262
}
6363

6464
public static function fromHex(string $hex): BinaryString

src/PublicKey/EllipticCurve.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,13 @@ private function isOnCurve(): bool
152152

153153
// This is only tested with P256 (secp256r1) but SHOULD be the same for
154154
// the other curves (none of which are supported yet)/
155-
$x3 = $x ** 3; // @phpstan-ignore binaryOp.invalid (phpstan/phpstan#12123)
156-
$ax = $a * $x; // @phpstan-ignore binaryOp.invalid
157-
$rhs = ($x3 + $ax + $b) % $p; // @phpstan-ignore binaryOp.invalid
155+
$x3 = $x ** 3; // @phpstan-ignore pow.leftNonNumeric, binaryOp.invalid (phpstan/phpstan#14288)
156+
$ax = $a * $x; // @phpstan-ignore mul.leftNonNumeric, mul.rightNonNumeric (phpstan/phpstan#14288)
157+
// @phpstan-ignore plus.rightNonNumeric, mod.rightNonNumeric, binaryOp.invalid (phpstan/phpstan#14288)
158+
$rhs = ($x3 + $ax + $b) % $p;
158159

159-
$y2 = $y ** 2; // @phpstan-ignore binaryOp.invalid
160-
$lhs = $y2 % $p; // @phpstan-ignore binaryOp.invalid
160+
$y2 = $y ** 2; // @phpstan-ignore pow.leftNonNumeric, binaryOp.invalid (phpstan/phpstan#14288)
161+
$lhs = $y2 % $p; // @phpstan-ignore mod.rightNonNumeric, binaryOp.invalid (phpstan/phpstan#14288)
161162

162163
// Functionaly, `$lhs === $rhs` but avoids reference equality issues
163164
// w/out having to introduce loose comparision ($lhs == $rhs works)

0 commit comments

Comments
 (0)