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

JsonGuardSchemaValidatorAdapter::getResult()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
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 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