EntityDefinitionValidator::validate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
ccs 8
cts 8
cp 1
rs 9.9
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of the CRUDlex package.
5
 *
6
 * (c) Philip Lehmann-Böhm <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CRUDlex;
13
14
use RomaricDrigon\MetaYaml\MetaYaml;
15
use RomaricDrigon\MetaYaml\Loader\YamlLoader;
16
17
/**
18
 * An entity definition validator using the romaricdrigon/MetaYaml validator with the
19
 * given definitionSchema.yml.
20
 */
21
class EntityDefinitionValidator implements EntityDefinitionValidatorInterface
22
{
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 79
    public function validate(array $data)
28
    {
29 79
        $loader        = new YamlLoader();
30 79
        $schemaContent = $loader->loadFromFile(__DIR__.'/../definitionSchema.yml');
31 79
        $schema        = new MetaYaml($schemaContent);
32
        try {
33 79
            $schema->validate($data);
34 1
        } catch (\Exception $e) {
35 1
            throw new \LogicException($e->getMessage(), $e->getCode(), $e);
36
        }
37 79
    }
38
39
}
40