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

JustinRainbowSchemaValidatorAdapter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 21
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 12 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