@@ -17,7 +17,43 @@ public function __construct(
1717 }
1818
1919 /**
20- * @param array[] $metadataPolicies
20+ * @return array<string,array<string,array<string,mixed>>>
21+ * @throws \SimpleSAML\OpenID\Exceptions\MetadataPolicyException
22+ * @psalm-suppress MixedAssignment
23+ */
24+ public function ensureFormat (array $ metadataPolicies ): array
25+ {
26+ foreach ($ metadataPolicies as $ entityType => $ metadataPolicyEntityType ) {
27+ if (!is_string ($ entityType )) {
28+ throw new MetadataPolicyException ('Invalid metadata policy format (entity type key). ' );
29+ }
30+ if (!is_array ($ metadataPolicyEntityType )) {
31+ throw new MetadataPolicyException ('Invalid metadata policy format (entity type value). ' );
32+ }
33+
34+ foreach ($ metadataPolicyEntityType as $ parameter => $ metadataPolicyParameter ) {
35+ if (!is_string ($ parameter )) {
36+ throw new MetadataPolicyException ('Invalid metadata policy format (parameter key). ' );
37+ }
38+ if (!is_array ($ metadataPolicyParameter )) {
39+ throw new MetadataPolicyException ('Invalid metadata policy format (parameter value). ' );
40+ }
41+
42+ $ operators = array_keys ($ metadataPolicyParameter );
43+ foreach ($ operators as $ operator ) {
44+ if (!is_string ($ operator )) {
45+ throw new MetadataPolicyException ('Invalid metadata policy format (operator key). ' );
46+ }
47+ }
48+ }
49+ }
50+
51+ /** @var array<string,array<string,array<string,mixed>>> $metadataPolicies */
52+ return $ metadataPolicies ;
53+ }
54+
55+ /**
56+ * @param array<array<string,array<string,array<string,mixed>>>> $metadataPolicies
2157 * @param string[] $criticalMetadataPolicyOperators
2258 *
2359 * @throws \SimpleSAML\OpenID\Exceptions\MetadataPolicyException
@@ -28,6 +64,7 @@ public function for(
2864 array $ metadataPolicies ,
2965 array $ criticalMetadataPolicyOperators = [],
3066 ): array {
67+ /** @var array<string,array<string,mixed>> $currentPolicy */
3168 $ currentPolicy = [];
3269 $ supportedOperators = MetadataPolicyOperatorsEnum::values ();
3370
@@ -63,15 +100,6 @@ public function for(
63100 // Go over each metadata parameter and resolve the policy.
64101 /** @psalm-suppress MixedAssignment We'll check if $nextPolicyParameterOperations is array type. */
65102 foreach ($ nextPolicy as $ nextPolicyParameter => $ nextPolicyParameterOperations ) {
66- if (!is_array ($ nextPolicyParameterOperations )) {
67- throw new MetadataPolicyException (
68- sprintf (
69- 'Invalid format for metadata policy operations encountered: %s ' ,
70- var_export ($ nextPolicyParameterOperations , true ),
71- ),
72- );
73- }
74-
75103 MetadataPolicyOperatorsEnum::validateGeneralParameterOperationRules ($ nextPolicyParameterOperations );
76104 MetadataPolicyOperatorsEnum::validateSpecificParameterOperationRules ($ nextPolicyParameterOperations );
77105
@@ -194,7 +222,7 @@ public function for(
194222 }
195223
196224 // Check if the current policy is in valid state after merge.
197- /** @var array $currentPolicyParameterOperations We ensured this is array. */
225+ /** @var array<string,array<string,mixed>> $currentPolicy */
198226 foreach ($ currentPolicy as $ currentPolicyParameterOperations ) {
199227 MetadataPolicyOperatorsEnum::validateGeneralParameterOperationRules (
200228 $ currentPolicyParameterOperations ,
0 commit comments