Completed
Push — master ( 7d90f1...0c951c )
by John
03:40
created

JsonGuardSchemaValidatorAdapter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 19
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getResult() 0 11 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 League\JsonGuard\Validator as JsonGuardSchemaValidator;
12
13
/**
14
 * @author John Kleijn <[email protected]>
15
 */
16
class JsonGuardSchemaValidatorAdapter extends SchemaValidatorAdapter
17
{
18
    /**
19
     * @param \stdClass $definition
20
     * @param  mixed    $value
21
     * @return ValidationResult
22
     */
23
    protected function getResult(\stdClass $definition, $value): ValidationResult
24
    {
25
        $validator = new JsonGuardSchemaValidator($value, $definition);
26
27
        $map = [];
28
        foreach ($validator->errors() as $error) {
29
            $map[$error->getDataPath()] = $error->getMessage();
30
        }
31
32
        return new ValidationResult(!$validator->fails(), $map);
33
    }
34
}
35