Validator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 41
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A registerXApiConstraints() 0 9 1
A createValidatorBuilder() 0 7 1
A createValidator() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[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 Xabbuh\XApi\Validator;
13
14
use Symfony\Component\Validator\ValidatorBuilder;
15
use Symfony\Component\Validator\ValidatorBuilderInterface;
16
use Symfony\Component\Validator\ValidatorInterface;
17
18
/**
19
 * Entry point to setup the {@link \Symfony\Component\Validator\Validator}
20
 * component for the Experience API.
21
 *
22
 * @author Christian Flothmann <[email protected]>
23
 */
24
class Validator
25
{
26
    /**
27
     * Registers validation constraints for the xAPI models on a ValidatorBuilder.
28
     *
29
     * @param ValidatorBuilderInterface $builder The ValidatorBuilder
30
     */
31 3
    public static function registerXApiConstraints(ValidatorBuilderInterface $builder)
32
    {
33 3
        $builder->addXmlMappings(array(
34 3
            __DIR__.'/../metadata/Activity.xml',
35
            __DIR__.'/../metadata/Agent.xml',
36
            __DIR__.'/../metadata/Group.xml',
37
            __DIR__.'/../metadata/Statement.xml',
38
        ));
39 3
    }
40
41
    /**
42
     * Creates a ValidationBuilder with validation constraints registered for
43
     * the xAPI models.
44
     *
45
     * @return ValidatorBuilderInterface The ValidatorBuilder
46
     */
47 2
    public static function createValidatorBuilder()
48
    {
49 2
        $builder = new ValidatorBuilder();
50 2
        static::registerXApiConstraints($builder);
51
52 2
        return $builder;
53
    }
54
55
    /**
56
     * Creates a new Validator.
57
     *
58
     * @return ValidatorInterface The Validator
59
     */
60 1
    public static function createValidator()
61
    {
62 1
        return static::createValidatorBuilder()->getValidator();
63
    }
64
}
65