@@ -202,38 +202,49 @@ public function getSupportedOperatorCombinations(): array
202202 $ this ->value ,
203203 ...match ($ this ) {
204204 self ::Value => [
205+ self ::Add->value ,
206+ self ::Default->value ,
207+ self ::OneOf->value ,
208+ self ::SubsetOf->value ,
209+ self ::SupersetOf->value ,
205210 self ::Essential->value ,
206211 ],
207212 self ::Add => [
213+ self ::Value->value ,
208214 self ::Default->value ,
209215 self ::SubsetOf->value ,
210216 self ::SupersetOf->value ,
211217 self ::Essential->value ,
212218 ],
213219 self ::Default => [
220+ self ::Value->value ,
214221 self ::Add->value ,
215222 self ::OneOf->value ,
216223 self ::SubsetOf->value ,
217224 self ::SupersetOf->value ,
218225 self ::Essential->value ,
219226 ],
220227 self ::OneOf => [
228+ self ::Value->value ,
221229 self ::Default->value ,
222230 self ::Essential->value ,
223231 ],
224232 self ::SubsetOf => [
233+ self ::Value->value ,
225234 self ::Add->value ,
226235 self ::Default->value ,
227236 self ::SupersetOf->value ,
228237 self ::Essential->value ,
229238 ],
230239 self ::SupersetOf => [
240+ self ::Value->value ,
231241 self ::Add->value ,
232242 self ::Default->value ,
233243 self ::SubsetOf->value ,
234244 self ::Essential->value ,
235245 ],
236246 self ::Essential => [
247+ self ::Value->value ,
237248 self ::Add->value ,
238249 self ::Default->value ,
239250 self ::OneOf->value ,
@@ -282,6 +293,7 @@ public static function validateGeneralParameterOperationRules(array $parameterOp
282293 ),
283294 );
284295 }
296+
285297 // If operator combination is not allowed, throw.
286298 if (!$ metadataPolicyOperatorsEnum ->isOperatorCombinationSupported ($ parameterOperatorKeys )) {
287299 throw new MetadataPolicyException (
@@ -311,19 +323,65 @@ public static function validateSpecificParameterOperationRules(array $parameterO
311323
312324 $ operatorValue = $ parameterOperations [$ metadataPolicyOperatorEnum ->value ];
313325
314- // No special resolving rules for operator 'value', continue with 'add'.
315- if ($ metadataPolicyOperatorEnum === MetadataPolicyOperatorsEnum::Add) {
316- /** @var array<mixed> $operatorValue We ensured this is array. */
317- // If add is combined with subset_of, the values of add MUST be a subset of the values of
326+ // Start with operator 'value'.
327+ if ($ metadataPolicyOperatorEnum === MetadataPolicyOperatorsEnum::Value) {
328+ // MAY be combined with add, in which case the values of add MUST be a subset of the values of value.
329+ if (
330+ in_array (MetadataPolicyOperatorsEnum::Add->value , $ parameterOperatorKeys , true )
331+ ) {
332+ /** @var array<mixed> $subset We ensured this is array. */
333+ $ subset = $ parameterOperations [MetadataPolicyOperatorsEnum::Add->value ];
334+ if (!MetadataPolicyOperatorsEnum::Value->isValueSupersetOf ($ operatorValue , $ subset )) {
335+ throw new MetadataPolicyException (
336+ sprintf (
337+ 'Operator %s, value %s is not superset of %s. ' ,
338+ $ metadataPolicyOperatorEnum ->value ,
339+ var_export ($ operatorValue , true ),
340+ var_export ($ subset , true ),
341+ ),
342+ );
343+ }
344+ }
345+
346+ // MAY be combined with default if the value of value is not null.
347+ if (
348+ in_array (MetadataPolicyOperatorsEnum::Default->value , $ parameterOperatorKeys , true ) &&
349+ is_null ($ operatorValue )
350+ ) {
351+ throw new MetadataPolicyException (
352+ sprintf (
353+ 'Operator %s, value null can not be combined with operator default. ' ,
354+ $ metadataPolicyOperatorEnum ->value ,
355+ ),
356+ );
357+ }
358+
359+ // MAY be combined with one_of, in which case the value of value MUST be among the one_of values.
360+ if (
361+ in_array (MetadataPolicyOperatorsEnum::OneOf->value , $ parameterOperatorKeys , true )
362+ ) {
363+ /** @var array<mixed> $oneOf We ensured this is array. */
364+ $ oneOf = $ parameterOperations [MetadataPolicyOperatorsEnum::OneOf->value ];
365+ if (!in_array ($ operatorValue , $ oneOf )) {
366+ throw new MetadataPolicyException (
367+ sprintf (
368+ 'Operator %s, value %s is not one of %s. ' ,
369+ $ metadataPolicyOperatorEnum ->value ,
370+ var_export ($ operatorValue , true ),
371+ var_export ($ oneOf , true ),
372+ ),
373+ );
374+ }
375+ }
376+
377+ // MAY be combined with subset_of, in which case the values of value MUST be a subset of the values of
318378 // subset_of.
319379 if (
320380 in_array (MetadataPolicyOperatorsEnum::SubsetOf->value , $ parameterOperatorKeys , true )
321381 ) {
322382 /** @var array<mixed> $superset We ensured this is array. */
323- $ superset = $ parameterOperations [
324- MetadataPolicyOperatorsEnum::SubsetOf->value
325- ];
326- if (!MetadataPolicyOperatorsEnum::Add->isValueSubsetOf ($ operatorValue , $ superset )) {
383+ $ superset = $ parameterOperations [MetadataPolicyOperatorsEnum::SubsetOf->value ];
384+ if (!MetadataPolicyOperatorsEnum::Value->isValueSubsetOf ($ operatorValue , $ superset )) {
327385 throw new MetadataPolicyException (
328386 sprintf (
329387 'Operator %s, value %s is not subset of %s. ' ,
@@ -334,20 +392,15 @@ public static function validateSpecificParameterOperationRules(array $parameterO
334392 );
335393 }
336394 }
337- // If add is combined with superset_of, the values of add MUST be a superset of the values
395+
396+ // MAY be combined with superset_of, in which case the values of value MUST be a superset of the values
338397 // of superset_of.
339398 if (
340- in_array (
341- MetadataPolicyOperatorsEnum::SupersetOf->value ,
342- $ parameterOperatorKeys ,
343- true ,
344- )
399+ in_array (MetadataPolicyOperatorsEnum::SupersetOf->value , $ parameterOperatorKeys , true )
345400 ) {
346401 /** @var array<mixed> $subset We ensured this is array. */
347- $ subset = $ parameterOperations [
348- MetadataPolicyOperatorsEnum::SupersetOf->value
349- ];
350- if (!MetadataPolicyOperatorsEnum::Add->isValueSupersetOf ($ operatorValue , $ subset )) {
402+ $ subset = $ parameterOperations [MetadataPolicyOperatorsEnum::SupersetOf->value ];
403+ if (!MetadataPolicyOperatorsEnum::Value->isValueSupersetOf ($ operatorValue , $ subset )) {
351404 throw new MetadataPolicyException (
352405 sprintf (
353406 'Operator %s, value %s is not superset of %s. ' ,
@@ -358,36 +411,36 @@ public static function validateSpecificParameterOperationRules(array $parameterO
358411 );
359412 }
360413 }
361- } elseif ( $ metadataPolicyOperatorEnum === MetadataPolicyOperatorsEnum::Default) {
362- // If default is combined with one_of, the default value MUST be among the one_of values .
414+
415+ // MAY be combined with essential, except when value is null and essential is true .
363416 if (
364- in_array (MetadataPolicyOperatorsEnum::OneOf ->value , $ parameterOperatorKeys , true )
417+ in_array (MetadataPolicyOperatorsEnum::Essential ->value , $ parameterOperatorKeys , true )
365418 ) {
366- /** @var array<mixed> $superset We ensured this is array. */
367- $ superset = $ parameterOperations [
368- MetadataPolicyOperatorsEnum::OneOf->value
369- ];
370- if (!MetadataPolicyOperatorsEnum::OneOf->isValueSubsetOf ($ operatorValue , $ superset )) {
419+ $ essential = $ parameterOperations [MetadataPolicyOperatorsEnum::Essential->value ];
420+ if ($ operatorValue === null && $ essential === true ) {
371421 throw new MetadataPolicyException (
372422 sprintf (
373- 'Operator %s, value %s is not one of %s . ' ,
423+ 'Operator %s, value %s can not be combined with essential value true . ' ,
374424 $ metadataPolicyOperatorEnum ->value ,
375425 var_export ($ operatorValue , true ),
376- var_export ($ superset , true ),
377426 ),
378427 );
379428 }
380429 }
381- // If default is combined with subset_of, the value of default MUST be a subset of the
382- // values of subset_of.
430+ } elseif ($ metadataPolicyOperatorEnum === MetadataPolicyOperatorsEnum::Add) {
431+ // MAY be combined with value, in which case the values of add MUST be a subset of the values of value.
432+ // We handle this in value case.
433+
434+ // MAY be combined with subset_of, in which case the values of add MUST be a subset of the values of
435+ // subset_of.
383436 if (
384437 in_array (MetadataPolicyOperatorsEnum::SubsetOf->value , $ parameterOperatorKeys , true )
385438 ) {
386439 /** @var array<mixed> $superset We ensured this is array. */
387440 $ superset = $ parameterOperations [
388441 MetadataPolicyOperatorsEnum::SubsetOf->value
389442 ];
390- if (!MetadataPolicyOperatorsEnum::Default ->isValueSubsetOf ($ operatorValue , $ superset )) {
443+ if (!MetadataPolicyOperatorsEnum::Add ->isValueSubsetOf ($ operatorValue , $ superset )) {
391444 throw new MetadataPolicyException (
392445 sprintf (
393446 'Operator %s, value %s is not subset of %s. ' ,
@@ -398,38 +451,22 @@ public static function validateSpecificParameterOperationRules(array $parameterO
398451 );
399452 }
400453 }
401- // If default is combined with superset_of, the values of default MUST be a superset of
402- // the values of superset_of.
403- if (
404- in_array (
405- MetadataPolicyOperatorsEnum::SupersetOf->value ,
406- $ parameterOperatorKeys ,
407- true ,
408- )
409- ) {
410- /** @var array<mixed> $subset We ensured this is array. */
411- $ subset = $ parameterOperations [
412- MetadataPolicyOperatorsEnum::SupersetOf->value
413- ];
414- if (!MetadataPolicyOperatorsEnum::Default->isValueSupersetOf ($ operatorValue , $ subset )) {
415- throw new MetadataPolicyException (
416- sprintf (
417- 'Operator %s, value %s is not superset of %s. ' ,
418- $ metadataPolicyOperatorEnum ->value ,
419- var_export ($ operatorValue , true ),
420- var_export ($ subset , true ),
421- ),
422- );
423- }
424- }
425454
426- // Operator one_of has special rule when combined with default, but we already handled that
427- // when we encountered default. We can continue to subset_of.
455+ // Operator default
456+ // MAY be combined with value if the value of value is not null. -> handled in value case.
457+
458+ // Operator one_of
459+ // MAY be combined with value, in which case the value of value MUST be among the one_of values. ->
460+ // handled in value case.
428461 } elseif ($ metadataPolicyOperatorEnum === MetadataPolicyOperatorsEnum::SubsetOf) {
429- // Operator subset_of has special rule when combined with add or default, but we already
430- // handled that. We'll only handle special case for superset_of.
431- // If subset_of is combined with superset_of, the values of subset_of MUST be a superset of
432- // the values of superset_of.
462+ // MAY be combined with value, in which case the values of value MUST be a subset of the values of
463+ // subset_of. -> handled in value case.
464+
465+ // MAY be combined with add, in which case the values of add MUST be a subset of the values of
466+ // subset_of. -> handled in add case.
467+
468+ // MAY be combined with superset_of, in which case the values of subset_of MUST be a superset of the
469+ // values of superset_of.
433470 if (
434471 in_array (
435472 MetadataPolicyOperatorsEnum::SupersetOf->value ,
@@ -453,8 +490,16 @@ public static function validateSpecificParameterOperationRules(array $parameterO
453490 }
454491 }
455492
456- // Operator superset_of has special rules when combined with add, default and subset_of,
457- // but we already handle those. Operator essential doesn't have any special rules.
493+ // Operator superset_of
494+ // MAY be combined with value, in which case the values of value MUST be a superset of the values of
495+ // superset_of. -> handled in value case.
496+ // MAY be combined with subset_of, in which case the values of subset_of MUST be a superset of the
497+ // values of superset_of. -> handled in subset_of case
498+
499+ // Operator essential
500+ // MAY be combined with value, except when value is null and essential is true. -> handled in value
501+ // case.
502+
458503 // We can continue with merging.
459504 }
460505 }
0 commit comments