Skip to content

Commit 71b51de

Browse files
committed
Apply phpstan level 6
1 parent e45656d commit 71b51de

File tree

13 files changed

+67
-25
lines changed

13 files changed

+67
-25
lines changed

src/Codebooks/MetadataPolicyOperatorsEnum.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ public static function validateGeneralParameterOperationRules(array $parameterOp
299299
}
300300

301301
/**
302+
* @param array<string,mixed> $parameterOperations
302303
* @throws \SimpleSAML\OpenID\Exceptions\MetadataPolicyException
303304
*/
304305
public static function validateSpecificParameterOperationRules(array $parameterOperations): void
@@ -316,13 +317,13 @@ public static function validateSpecificParameterOperationRules(array $parameterO
316317

317318
// No special resolving rules for operator 'value', continue with 'add'.
318319
if ($metadataPolicyOperatorEnum === MetadataPolicyOperatorsEnum::Add) {
319-
/** @var array $operatorValue We ensured this is array. */
320+
/** @var array<mixed> $operatorValue We ensured this is array. */
320321
// If add is combined with subset_of, the values of add MUST be a subset of the values of
321322
// subset_of.
322323
if (
323324
in_array(MetadataPolicyOperatorsEnum::SubsetOf->value, $parameterOperatorKeys, true)
324325
) {
325-
/** @var array $superset We ensured this is array. */
326+
/** @var array<mixed> $superset We ensured this is array. */
326327
$superset = $parameterOperations[
327328
MetadataPolicyOperatorsEnum::SubsetOf->value
328329
];
@@ -346,7 +347,7 @@ public static function validateSpecificParameterOperationRules(array $parameterO
346347
true,
347348
)
348349
) {
349-
/** @var array $subset We ensured this is array. */
350+
/** @var array<mixed> $subset We ensured this is array. */
350351
$subset = $parameterOperations[
351352
MetadataPolicyOperatorsEnum::SupersetOf->value
352353
];
@@ -366,7 +367,7 @@ public static function validateSpecificParameterOperationRules(array $parameterO
366367
if (
367368
in_array(MetadataPolicyOperatorsEnum::OneOf->value, $parameterOperatorKeys, true)
368369
) {
369-
/** @var array $superset We ensured this is array. */
370+
/** @var array<mixed> $superset We ensured this is array. */
370371
$superset = $parameterOperations[
371372
MetadataPolicyOperatorsEnum::OneOf->value
372373
];
@@ -386,7 +387,7 @@ public static function validateSpecificParameterOperationRules(array $parameterO
386387
if (
387388
in_array(MetadataPolicyOperatorsEnum::SubsetOf->value, $parameterOperatorKeys, true)
388389
) {
389-
/** @var array $superset We ensured this is array. */
390+
/** @var array<mixed> $superset We ensured this is array. */
390391
$superset = $parameterOperations[
391392
MetadataPolicyOperatorsEnum::SubsetOf->value
392393
];
@@ -410,7 +411,7 @@ public static function validateSpecificParameterOperationRules(array $parameterO
410411
true,
411412
)
412413
) {
413-
/** @var array $subset We ensured this is array. */
414+
/** @var array<mixed> $subset We ensured this is array. */
414415
$subset = $parameterOperations[
415416
MetadataPolicyOperatorsEnum::SupersetOf->value
416417
];
@@ -440,7 +441,7 @@ public static function validateSpecificParameterOperationRules(array $parameterO
440441
true,
441442
)
442443
) {
443-
/** @var array $subset We ensured this is array. */
444+
/** @var array<mixed> $subset We ensured this is array. */
444445
$subset = $parameterOperations[
445446
MetadataPolicyOperatorsEnum::SupersetOf->value
446447
];

src/Federation/EntityStatement.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function getExpirationTime(): int
8181

8282
/**
8383
* @throws \SimpleSAML\OpenID\Exceptions\JwsException
84-
* @return array[]
84+
* @return array{keys:array<array<string,mixed>>}
8585
* @psalm-suppress MixedReturnTypeCoercion
8686
*/
8787
public function getJwks(): array
@@ -98,6 +98,12 @@ public function getJwks(): array
9898
throw new JwsException('Invalid JWKS encountered: ' . var_export($jwks, true));
9999
}
100100

101+
$jwks[ClaimsEnum::Keys->value] = array_map(
102+
$this->helpers->arr()->ensureStringKeys(...),
103+
$jwks[ClaimsEnum::Keys->value],
104+
);
105+
106+
/** @var array{keys:array<array<string,mixed>>} $jwks */
101107
return $jwks;
102108
}
103109

@@ -153,6 +159,7 @@ public function getAuthorityHints(): ?array
153159
}
154160

155161
/**
162+
* @return ?array<string,mixed>
156163
* @throws \SimpleSAML\OpenID\Exceptions\JwsException
157164
* @throws \SimpleSAML\OpenID\Exceptions\EntityStatementException
158165
*/
@@ -172,12 +179,13 @@ public function getMetadata(): ?array
172179
throw new EntityStatementException('Invalid Metadata claim.');
173180
}
174181

175-
return $metadata;
182+
return $this->helpers->arr()->ensureStringKeys($metadata);
176183
}
177184

178185
/**
179186
* @throws \SimpleSAML\OpenID\Exceptions\JwsException
180187
* @throws \SimpleSAML\OpenID\Exceptions\EntityStatementException
188+
* @phpstan-ignore missingType.iterableValue (We will ensure proper format in policy resolver.)
181189
*/
182190
public function getMetadataPolicy(): ?array
183191
{
@@ -273,6 +281,7 @@ public function isConfiguration(): bool
273281

274282
/**
275283
* @throws \SimpleSAML\OpenID\Exceptions\JwsException
284+
* @phpstan-ignore missingType.iterableValue (Format is validated later.)
276285
*/
277286
public function verifyWithKeySet(?array $jwks = null, int $signatureIndex = 0): void
278287
{

src/Federation/EntityStatement/TrustMarkClaim.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public function getTrustMark(): TrustMark
5959
return $this->trustMark;
6060
}
6161

62+
/**
63+
* @return array<string,mixed>
64+
*/
6265
public function getOtherClaims(): array
6366
{
6467
return $this->otherClaims;

src/Federation/MetadataPolicyApplicator.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,24 @@ public function __construct(
1717
}
1818

1919
/**
20-
* @param array $resolvedMetadataPolicy Resolved (validated) metadata policy.
20+
* @param array<string,array<string,mixed>> $resolvedMetadataPolicy Resolved (validated) metadata policy.
21+
* @param array<string,mixed> $metadata
22+
* @return array<string,mixed> Metadata with applied policies.
2123
* @throws \SimpleSAML\OpenID\Exceptions\MetadataPolicyException
2224
* @throws \SimpleSAML\OpenID\Exceptions\OpenIdException
2325
*/
2426
public function for(
2527
array $resolvedMetadataPolicy,
2628
array $metadata,
2729
): array {
28-
/**
29-
* @var string $policyParameterName
30-
* @var array<string,mixed> $policyOperations
31-
*/
3230
foreach ($resolvedMetadataPolicy as $policyParameterName => $policyOperations) {
3331
foreach (MetadataPolicyOperatorsEnum::cases() as $metadataPolicyOperatorEnum) {
3432
if (!array_key_exists($metadataPolicyOperatorEnum->value, $policyOperations)) {
3533
continue;
3634
}
3735
/** @psalm-suppress MixedAssignment */
3836
$operatorValue = $policyOperations[$metadataPolicyOperatorEnum->value];
39-
/** @psalm-suppress MixedAssignment */
37+
/** @psalm-suppress MixedAssignment, MixedArgumentTypeCoercion */
4038
$metadataParameterValueBeforePolicy = $this->resolveParameterValueBeforePolicy(
4139
$metadata,
4240
$policyParameterName,
@@ -99,7 +97,7 @@ public function for(
9997
$policyParameterName,
10098
);
10199

102-
/** @var array $operatorValue */
100+
/** @var array<mixed> $operatorValue Set bc of phpstan */
103101
if (!in_array($metadataParameterValueBeforePolicy, $operatorValue, true)) {
104102
throw new MetadataPolicyException(
105103
sprintf(
@@ -152,7 +150,7 @@ public function for(
152150
$policyParameterName,
153151
);
154152

155-
/** @var array $operatorValue */
153+
/** @var array<mixed> $operatorValue Set bc of phpstan */
156154
if (
157155
!$metadataPolicyOperatorEnum->isValueSupersetOf(
158156
$metadataParameterValueBeforePolicy,
@@ -190,9 +188,13 @@ public function for(
190188
}
191189
}
192190

191+
/** @var array<string,mixed> $metadata */
193192
return $metadata;
194193
}
195194

195+
/**
196+
* @param array<string,mixed> $metadata
197+
*/
196198
protected function resolveParameterValueBeforePolicy(array $metadata, string $parameter): mixed
197199
{
198200
/** @psalm-suppress MixedAssignment */

src/Federation/MetadataPolicyResolver.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function __construct(
2020
* @return array<string,array<string,array<string,mixed>>>
2121
* @throws \SimpleSAML\OpenID\Exceptions\MetadataPolicyException
2222
* @psalm-suppress MixedAssignment
23+
* @phpstan-ignore missingType.iterableValue (We validate it here)
2324
*/
2425
public function ensureFormat(array $metadataPolicies): array
2526
{
@@ -55,7 +56,7 @@ public function ensureFormat(array $metadataPolicies): array
5556
/**
5657
* @param array<array<string,array<string,array<string,mixed>>>> $metadataPolicies
5758
* @param string[] $criticalMetadataPolicyOperators
58-
*
59+
* @return array<string,array<string,mixed>>
5960
* @throws \SimpleSAML\OpenID\Exceptions\MetadataPolicyException
6061
* @throws \SimpleSAML\OpenID\Exceptions\OpenIdException
6162
*/
@@ -72,6 +73,7 @@ public function for(
7273
/** @psalm-suppress MixedAssignment We'll check if $nextPolicy is array type. */
7374
if (
7475
(!array_key_exists($entityTypeEnum->value, $metadataPolicy)) ||
76+
/** @phpstan-ignore booleanNot.alwaysFalse (Let's check for validity here.) */
7577
(!is_array($nextPolicy = $metadataPolicy[$entityTypeEnum->value]))
7678
) {
7779
continue;

src/Federation/RequestObject.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,22 @@ public function getExpirationTime(): int
6666
}
6767

6868
/**
69+
* @return ?string[]
6970
* @throws \SimpleSAML\OpenID\Exceptions\JwsException
7071
* @throws \SimpleSAML\OpenID\Exceptions\RequestObjectException
7172
*/
7273
public function getTrustChain(): ?array
7374
{
75+
$claimKey = ClaimsEnum::TrustChain->value;
7476
/** @psalm-suppress MixedAssignment */
75-
$trustChain = $this->getPayloadClaim(ClaimsEnum::TrustChain->value) ?? null;
77+
$trustChain = $this->getPayloadClaim($claimKey) ?? null;
7678

7779
if (is_null($trustChain)) {
7880
return null;
7981
}
8082

8183
if (is_array($trustChain)) {
82-
return $trustChain;
84+
return $this->ensureNonEmptyStrings($trustChain, $claimKey);
8385
}
8486

8587
throw new RequestObjectException(

src/Federation/TrustChain.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ class TrustChain implements JsonSerializable
4343
/**
4444
* Resolved metadata policy per entity type.
4545
*
46-
* @var array[]
46+
* @var array<string,array<string,array<string,mixed>>>
4747
*/
4848
protected array $resolvedMetadataPolicy = [];
4949

5050
/**
5151
* Resolved metadata (after applying resolved policy) per entity type.
5252
*
53-
* @var array<string,null|array>
53+
* @var array<string,null|array<string,mixed>>
5454
*/
5555
protected array $resolvedMetadata = [];
5656

@@ -122,6 +122,7 @@ public function getResolvedTrustAnchor(): EntityStatement
122122
}
123123

124124
/**
125+
* @return ?array<string,mixed>
125126
* @throws \SimpleSAML\OpenID\Exceptions\TrustChainException
126127
* @throws \SimpleSAML\OpenID\Exceptions\JwsException
127128
* @throws \SimpleSAML\OpenID\Exceptions\OpenIdException
@@ -433,17 +434,22 @@ protected function resolveMetadataFor(EntityTypesEnum $entityTypeEnum): void
433434
// to it.
434435
/** @psalm-suppress RiskyTruthyFalsyComparison */
435436
if (empty($this->resolvedMetadataPolicy[$entityTypeEnum->value])) {
437+
/** @var array<string,mixed> $leafMetadataEntityType */
436438
$this->resolvedMetadata[$entityTypeEnum->value] = $leafMetadataEntityType;
437439
return;
438440
}
439441

440442
// Policy application to leaf metadata.
443+
/** @var array<string,mixed> $leafMetadataEntityType */
441444
$this->resolvedMetadata[$entityTypeEnum->value] = $this->metadataPolicyApplicator->for(
442445
$this->resolvedMetadataPolicy[$entityTypeEnum->value],
443446
$leafMetadataEntityType,
444447
);
445448
}
446449

450+
/**
451+
* @return \SimpleSAML\OpenID\Federation\EntityStatement[]
452+
*/
447453
public function getEntities(): array
448454
{
449455
return $this->entities;

src/Federation/TrustChainResolver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ public function for(string $entityId, array $validTrustAnchorIds): TrustChainBag
288288

289289
/**
290290
* @throws \SimpleSAML\OpenID\Exceptions\TrustChainException
291+
* @phpstan-ignore missingType.iterableValue (We validate it here)
291292
*/
292293
protected function validateStart(string $entityId, array $validTrustAnchorIds): void
293294
{

src/Helpers/Arr.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
class Arr
1010
{
11+
/**
12+
* @phpstan-ignore missingType.iterableValue (We can handle mixed type)
13+
*/
1114
public function ensureArrayDepth(array &$array, int|string ...$keys): void
1215
{
1316
if (count($keys) > 99) {
@@ -30,6 +33,7 @@ public function ensureArrayDepth(array &$array, int|string ...$keys): void
3033

3134
/**
3235
* @return array<string,mixed>
36+
* @phpstan-ignore missingType.iterableValue (We can handle mixed type)
3337
*/
3438
public function ensureStringKeys(array $array): array
3539
{

src/Helpers/Url.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public function isValid(string $url): bool
1414

1515
/**
1616
* Add (new) params to URL while preserving existing ones (if any).
17+
* @param array<string,mixed> $params
1718
*/
1819
public function withParams(string $url, array $params): string
1920
{

0 commit comments

Comments
 (0)