Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
14 / 14 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
SchemaValidation | |
100.00% |
14 / 14 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
1 / 1 |
setValidationError | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
setSchemaName | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
setMessages | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | namespace BO\Zmsentities\Exception; |
4 | |
5 | use BO\Zmsentities\Schema\Validator; |
6 | |
7 | /** |
8 | * example class to generate an exception |
9 | */ |
10 | class SchemaValidation extends \Exception |
11 | { |
12 | protected $code = 400; |
13 | |
14 | public $data = []; |
15 | |
16 | protected $schemaName = ''; |
17 | |
18 | public function setValidationError(array $validationErrorList) |
19 | { |
20 | $this->setMessages($validationErrorList); |
21 | return $this; |
22 | } |
23 | |
24 | public function setSchemaName($schemaName) |
25 | { |
26 | $this->schemaName = $schemaName . '.json'; |
27 | $this->template = $schemaName; |
28 | return $this; |
29 | } |
30 | |
31 | protected function setMessages($validationErrorList) |
32 | { |
33 | foreach ($validationErrorList as $error) { |
34 | $pointer = Validator::getOriginPointer($error); |
35 | $this->data[$pointer]['messages'][$error->getKeyword()] = $error->getMessage(); |
36 | $this->data[$pointer]['headline'] = $error->getDataPath(); |
37 | $this->data[$pointer]['failed'] = 1; |
38 | $this->data[$pointer]['data'] = $error->getData(); |
39 | } |
40 | $message = '[property ' . $error->getDataPath() . '] ' . json_encode($this->data[$pointer]['messages'], 1); |
41 | $this->message = (! $this->message) ? $message : $this->message; |
42 | return $this; |
43 | } |
44 | } |