Conditions | 7 |
Paths | 33 |
Total Lines | 18 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php namespace CMPayments\SchemaValidator\Validators; |
||
20 | public function validateEnum($data, $schema, $path) |
||
21 | { |
||
22 | if (!isset($schema->enum)) { |
||
23 | return; |
||
24 | } |
||
25 | |||
26 | // if $data comes from an array than the action below has already been done in validateArray() |
||
27 | $needle = (isset($schema->caseSensitive) && !$schema->caseSensitive) ? strtolower($data) : $data; |
||
28 | $haystack = (isset($schema->caseSensitive) && !$schema->caseSensitive) ? array_map('strtolower', $schema->enum) : $schema->enum; |
||
29 | |||
30 | if (!in_array($needle, $haystack)) { |
||
31 | |||
32 | $this->addError( |
||
33 | ValidateException::ERROR_USER_ENUM_NEEDLE_NOT_FOUND_IN_HAYSTACK, |
||
34 | [$path, $data, $this->conjugationObject(count($schema->enum), 'this specific value', 'one of these values'), implode('\', \'', $schema->enum)] |
||
35 | ); |
||
36 | } |
||
37 | } |
||
38 | |||
57 | } |