Completed
Push — master ( bca24d...1b0d8b )
by John
03:18
created

JustinRainbowSchemaValidatorAdapter::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 2
1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of the KleijnWeb\PhpApi\Descriptions package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\PhpApi\Descriptions\Description\Schema\Validator;
10
11
use JsonSchema\Validator as JustinRainbowJsonSchemaValidator;
12
use KleijnWeb\PhpApi\Descriptions\Description\Schema\Schema;
13
14
/**
15
 * @author John Kleijn <[email protected]>
16
 */
17
class JustinRainbowSchemaValidatorAdapter implements SchemaValidator
18
{
19
    /**
20
     * @param Schema $schema
21
     * @param mixed  $value
22
     *
23
     * @return ValidationResult
24
     */
25
    public function validate(Schema $schema, $value): ValidationResult
26
    {
27
        $validator = new JustinRainbowJsonSchemaValidator();
28
        $validator->check($value, $schema->getDefinition());
29
30
        $map = [];
31
        foreach ($validator->getErrors() as $error) {
32
            $map[$error['property']] = $error['message'];
33
        }
34
35
        return new ValidationResult($validator->isValid(), $map);
36
    }
37
}
38