Skip to content

Commit 9c61cc4

Browse files
committed
Fix phpstan issues
1 parent f6e40f9 commit 9c61cc4

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

phpstan-baseline.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
'count' => 1,
1414
'path' => __DIR__ . '/src/Nexus/Option/functions.php',
1515
];
16+
$ignoreErrors[] = [
17+
'rawMessage' => 'Parameter #3 ...$values of function sprintf expects bool|float|int|string|null, mixed given.',
18+
'identifier' => 'argument.type',
19+
'count' => 1,
20+
'path' => __DIR__ . '/src/Nexus/Password/Hash/Pbkdf2Hash.php',
21+
];
1622
$ignoreErrors[] = [
1723
'rawMessage' => 'Method Nexus\\Tests\\AutoReview\\ComposerJsonTest::getComposer() should return array<string, mixed> but returns mixed.',
1824
'identifier' => 'return.type',

phpstan.dist.neon

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ parameters:
2121
- tools/vendor/**
2222
bootstrapFiles:
2323
- vendor/autoload.php
24+
checkBenevolentUnionTypes: true
2425
checkMissingCallableSignature: true
2526
checkMissingOverrideMethodAttribute: true
27+
checkStrictPrintfPlaceholderTypes: false
2628
checkTooWideReturnTypesInProtectedAndPublicMethods: true
2729
checkUninitializedProperties: true
28-
checkBenevolentUnionTypes: true
2930
reportAlwaysTrueInLastCondition: true
3031
reportAnyTypeWideningInVarTag: true
3132
treatPhpDocTypesAsCertain: false

src/Nexus/Password/Hash/Pbkdf2Hash.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@
1919

2020
final readonly class Pbkdf2Hash extends AbstractHash implements SaltedHashInterface
2121
{
22-
private const array ALLOWED_ALGORITHMS = [
22+
/**
23+
* @internal
24+
*/
25+
public const array ALLOWED_ALGORITHMS = [
2326
Algorithm::Pbkdf2HmacSha1,
2427
Algorithm::Pbkdf2HmacSha256,
2528
Algorithm::Pbkdf2HmacSha512,
2629
];
30+
2731
private const int DEFAULT_LENGTH = 40;
2832
private const int MINIMUM_LENGTH = 0;
2933
private const int MINIMUM_ITERATIONS = 1_000;
@@ -39,6 +43,7 @@
3943
private int $length;
4044

4145
/**
46+
* @param value-of<self::ALLOWED_ALGORITHMS> $algorithm
4247
* @param array{
4348
* iterations?: int,
4449
* length?: int,
@@ -62,7 +67,6 @@ public function __construct(
6267
}
6368

6469
$validatedOptions = self::validatedOptions($options, $this->defaultIterations(), self::DEFAULT_LENGTH);
65-
6670
$this->iterations = $validatedOptions['iterations'];
6771
$this->length = $validatedOptions['length'];
6872
}
@@ -183,7 +187,7 @@ private function defaultIterations(): int
183187
return match ($this->algorithm) {
184188
Algorithm::Pbkdf2HmacSha1 => 1_300_000,
185189
Algorithm::Pbkdf2HmacSha256 => 600_000,
186-
default => 210_000,
190+
Algorithm::Pbkdf2HmacSha512 => 210_000,
187191
};
188192
}
189193

tests/Password/Hash/Pbkdf2HashTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testInvalidAlgorithm(): void
3636
$this->expectException(HashException::class);
3737
$this->expectExceptionMessage('Algorithm expected to be any of Algorith::Pbkdf2HmacSha1, Algorith::Pbkdf2HmacSha256, Algorith::Pbkdf2HmacSha512, but Algorithm::Argon2i given.');
3838

39-
new Pbkdf2Hash(Algorithm::Argon2i);
39+
new Pbkdf2Hash(Algorithm::Argon2i); // @phpstan-ignore argument.type
4040
}
4141

4242
public function testInvalidIterations(): void
@@ -55,6 +55,9 @@ public function testInvalidLength(): void
5555
new Pbkdf2Hash(Algorithm::Pbkdf2HmacSha512, ['length' => -1]);
5656
}
5757

58+
/**
59+
* @param value-of<Pbkdf2Hash::ALLOWED_ALGORITHMS> $algorithm
60+
*/
5861
#[DataProvider('provideDefaultIterationsCases')]
5962
public function testDefaultIterations(Algorithm $algorithm, int $iterations): void
6063
{

0 commit comments

Comments
 (0)