@@ -137,25 +137,37 @@ public function getSupportedParameterContainedValueTypes(): array
137137
138138
139139 /**
140- * @phpstan-ignore missingType.iterableValue (We can handle mixed type using array_diff)
140+ * @param mixed[] $superset
141141 */
142142 public function isValueSubsetOf (mixed $ value , array $ superset ): bool
143143 {
144144 $ value = is_array ($ value ) ? $ value : [$ value ];
145145
146- return array_diff ($ value , $ superset ) === [];
146+ foreach ($ value as $ item ) {
147+ if (!in_array ($ item , $ superset , true )) {
148+ return false ;
149+ }
150+ }
151+
152+ return true ;
147153 }
148154
149155
150156 /**
151- * @phpstan-ignore missingType.iterableValue (We can handle mixed type using array_diff)
157+ * @param mixed[] $subset
152158 */
153159 public function isValueSupersetOf (mixed $ value , array $ subset ): bool
154160 {
155161 $ value = is_array ($ value ) ? $ value : [$ value ];
156162
157- // Like subset, but from different perspective.
158- return array_diff ($ subset , $ value ) === [];
163+ // Like subset, but from a different perspective.
164+ foreach ($ subset as $ item ) {
165+ if (!in_array ($ item , $ value , true )) {
166+ return false ;
167+ }
168+ }
169+
170+ return true ;
159171 }
160172
161173
@@ -301,7 +313,7 @@ public static function validateGeneralParameterOperationRules(array $parameterOp
301313
302314 $ operatorValue = $ parameterOperations [$ metadataPolicyOperatorsEnum ->value ];
303315 // Check common policy resolving rules for each supported operator.
304- // If operator value type is not supported, throw.
316+ // If an operator value type is not supported, throw.
305317 if (!$ metadataPolicyOperatorsEnum ->isOperatorValueTypeSupported ($ operatorValue )) {
306318 throw new MetadataPolicyException (
307319 sprintf (
@@ -312,7 +324,7 @@ public static function validateGeneralParameterOperationRules(array $parameterOp
312324 );
313325 }
314326
315- // If operator combination is not allowed, throw.
327+ // If an operator combination is not allowed, throw.
316328 if (!$ metadataPolicyOperatorsEnum ->isOperatorCombinationSupported ($ parameterOperatorKeys )) {
317329 throw new MetadataPolicyException (
318330 sprintf (
@@ -342,13 +354,14 @@ public static function validateSpecificParameterOperationRules(array $parameterO
342354
343355 $ operatorValue = $ parameterOperations [$ metadataPolicyOperatorEnum ->value ];
344356
345- // Start with operator 'value'.
357+ // Start with the operator 'value'.
346358 if ($ metadataPolicyOperatorEnum === MetadataPolicyOperatorsEnum::Value) {
347- // MAY be combined with add, in which case the values of add MUST be a subset of the values of value.
359+ // MAY be combined with 'add', in which case the values of 'add' MUST be a subset of the values
360+ // of value.
348361 if (
349362 in_array (MetadataPolicyOperatorsEnum::Add->value , $ parameterOperatorKeys , true )
350363 ) {
351- /** @var array<mixed> $subset We ensured this is array. */
364+ /** @var array<mixed> $subset We ensured this is an array. */
352365 $ subset = $ parameterOperations [MetadataPolicyOperatorsEnum::Add->value ];
353366 if (!MetadataPolicyOperatorsEnum::Value->isValueSupersetOf ($ operatorValue , $ subset )) {
354367 throw new MetadataPolicyException (
@@ -362,7 +375,7 @@ public static function validateSpecificParameterOperationRules(array $parameterO
362375 }
363376 }
364377
365- // MAY be combined with default if the value of value is not null.
378+ // MAY be combined with default if the value of ' value' is not null.
366379 if (
367380 in_array (MetadataPolicyOperatorsEnum::Default->value , $ parameterOperatorKeys , true ) &&
368381 is_null ($ operatorValue )
@@ -379,7 +392,7 @@ public static function validateSpecificParameterOperationRules(array $parameterO
379392 if (
380393 in_array (MetadataPolicyOperatorsEnum::OneOf->value , $ parameterOperatorKeys , true )
381394 ) {
382- /** @var array<mixed> $oneOf We ensured this is array. */
395+ /** @var array<mixed> $oneOf We ensured this is an array. */
383396 $ oneOf = $ parameterOperations [MetadataPolicyOperatorsEnum::OneOf->value ];
384397 if (!in_array ($ operatorValue , $ oneOf )) {
385398 throw new MetadataPolicyException (
@@ -398,7 +411,7 @@ public static function validateSpecificParameterOperationRules(array $parameterO
398411 if (
399412 in_array (MetadataPolicyOperatorsEnum::SubsetOf->value , $ parameterOperatorKeys , true )
400413 ) {
401- /** @var array<mixed> $superset We ensured this is array. */
414+ /** @var array<mixed> $superset We ensured this is an array. */
402415 $ superset = $ parameterOperations [MetadataPolicyOperatorsEnum::SubsetOf->value ];
403416 if (!MetadataPolicyOperatorsEnum::Value->isValueSubsetOf ($ operatorValue , $ superset )) {
404417 throw new MetadataPolicyException (
@@ -417,7 +430,7 @@ public static function validateSpecificParameterOperationRules(array $parameterO
417430 if (
418431 in_array (MetadataPolicyOperatorsEnum::SupersetOf->value , $ parameterOperatorKeys , true )
419432 ) {
420- /** @var array<mixed> $subset We ensured this is array. */
433+ /** @var array<mixed> $subset We ensured this is an array. */
421434 $ subset = $ parameterOperations [MetadataPolicyOperatorsEnum::SupersetOf->value ];
422435 if (!MetadataPolicyOperatorsEnum::Value->isValueSupersetOf ($ operatorValue , $ subset )) {
423436 throw new MetadataPolicyException (
@@ -447,15 +460,15 @@ public static function validateSpecificParameterOperationRules(array $parameterO
447460 }
448461 }
449462 } elseif ($ metadataPolicyOperatorEnum === MetadataPolicyOperatorsEnum::Add) {
450- // MAY be combined with value, in which case the values of add MUST be a subset of the values of value.
451- // We handle this in value case.
463+ // MAY be combined with value, in which case the values of ' add' MUST be a subset of the values of
464+ // 'value'. We handle this in value case.
452465
453- // MAY be combined with subset_of, in which case the values of add MUST be a subset of the values of
466+ // MAY be combined with subset_of, in which case the values of ' add' MUST be a subset of the values of
454467 // subset_of.
455468 if (
456469 in_array (MetadataPolicyOperatorsEnum::SubsetOf->value , $ parameterOperatorKeys , true )
457470 ) {
458- /** @var array<mixed> $superset We ensured this is array. */
471+ /** @var array<mixed> $superset We ensured this is an array. */
459472 $ superset = $ parameterOperations [
460473 MetadataPolicyOperatorsEnum::SubsetOf->value
461474 ];
@@ -481,8 +494,8 @@ public static function validateSpecificParameterOperationRules(array $parameterO
481494 // MAY be combined with value, in which case the values of value MUST be a subset of the values of
482495 // subset_of. -> handled in value case.
483496
484- // MAY be combined with add, in which case the values of add MUST be a subset of the values of
485- // subset_of. -> handled in add case.
497+ // MAY be combined with ' add' , in which case the values of ' add' MUST be a subset of the values of
498+ // subset_of. -> handled in the ' add' case.
486499
487500 // MAY be combined with superset_of, in which case the values of subset_of MUST be a superset of the
488501 // values of superset_of.
@@ -493,7 +506,7 @@ public static function validateSpecificParameterOperationRules(array $parameterO
493506 true ,
494507 )
495508 ) {
496- /** @var array<mixed> $subset We ensured this is array. */
509+ /** @var array<mixed> $subset We ensured this is an array. */
497510 $ subset = $ parameterOperations [
498511 MetadataPolicyOperatorsEnum::SupersetOf->value
499512 ];
0 commit comments