Validator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 34
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 7 1
A __construct() 0 6 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arnaud
5
 * Date: 12/11/15
6
 * Time: 20:21
7
 */
8
9
namespace Ndrx\Profiler\Collectors;
10
11
use Symfony\Component\OptionsResolver\Exception\AccessException;
12
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
13
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
14
use Symfony\Component\OptionsResolver\Exception\NoSuchOptionException;
15
use Symfony\Component\OptionsResolver\Exception\OptionDefinitionException;
16
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;
17
use Symfony\Component\OptionsResolver\OptionsResolver;
18
19
class Validator
20
{
21
    /**
22
     * @var OptionsResolver
23
     */
24
    protected $optionResolver;
25
26 180
    public function __construct(array $required)
27
    {
28 180
        $this->optionResolver = new OptionsResolver();
29 180
        $this->optionResolver->setDefaults(array_fill_keys($required, null));
30 180
        $this->optionResolver->setRequired($required);
31 180
    }
32
33
    /**
34
     * @param array $data
35
     * @throws UndefinedOptionsException If an option name is undefined
36
     * @throws InvalidOptionsException   If an option doesn't fulfill the
37
     *                                   specified validation rules
38
     * @throws MissingOptionsException   If a required option is missing
39
     * @throws OptionDefinitionException If there is a cyclic dependency between
40
     *                                   lazy options and/or normalizers
41
     * @throws NoSuchOptionException     If a lazy option reads an unavailable option
42
     * @throws AccessException           If called from a lazy option or normalizer
43
     * @return bool
44
     */
45 16
    public function validate(array $data)
46
    {
47 16
        $this->optionResolver->resolve($data);
48 16
        $this->optionResolver->clear();
49
50 16
        return true;
51
    }
52
}
53