Conditions | 7 |
Paths | 16 |
Total Lines | 30 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Tests | 23 |
CRAP Score | 7 |
Changes | 0 |
1 | <?php |
||
32 | 21 | public function apply($instance, stdClass $schema, Context $context, Walker $walker) |
|
33 | { |
||
34 | 21 | $accumulatingContext = $context->duplicate(false); |
|
35 | 21 | $hasMatch = false; |
|
36 | 21 | $hasDoubleMatch = false; |
|
37 | |||
38 | 21 | foreach ($schema->oneOf as $subSchema) { |
|
39 | 21 | $subContext = $context->duplicate(false); |
|
40 | 21 | $walker->applyConstraints($instance, $subSchema, $subContext); |
|
41 | |||
42 | 21 | if ($subContext->countViolations() === 0) { |
|
43 | 16 | if (!$hasMatch) { |
|
44 | 16 | $hasMatch = true; |
|
45 | 16 | } else { |
|
46 | 4 | $hasDoubleMatch = true; |
|
47 | 4 | break; |
|
48 | } |
||
49 | 16 | } else { |
|
50 | 14 | $accumulatingContext->mergeViolations($subContext); |
|
51 | } |
||
52 | 21 | } |
|
53 | |||
54 | 21 | if (!$hasMatch) { |
|
55 | 6 | $context->mergeViolations($accumulatingContext); |
|
56 | 6 | } |
|
57 | |||
58 | 21 | if (!$hasMatch || $hasDoubleMatch) { |
|
59 | 10 | $context->addViolation('instance must match exactly one of the schemas listed in oneOf'); |
|
60 | 10 | } |
|
61 | 21 | } |
|
62 | } |
||
63 |