ValidatorManager   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A validate() 0 9 2
1
<?php
2
3
/**
4
 * Copyright 2014 Jonathan Bouzekri. All rights reserved.
5
 *
6
 * @copyright Copyright 2014 Jonathan Bouzekri <[email protected]>
7
 * @license https://github.com/jbouzekri/FileUploaderBundle/blob/master/LICENSE
8
 * @link https://github.com/jbouzekri/FileUploaderBundle
9
 */
10
11
namespace Jb\Bundle\FileUploaderBundle\Service;
12
13
use Jb\Bundle\FileUploaderBundle\Service\ValidatorChain;
14
use Jb\Bundle\FileUploaderBundle\Service\EndpointConfiguration;
15
16
/**
17
 * ValidatorManager
18
 *
19
 * @author jobou
20
 */
21
class ValidatorManager
22
{
23
    /**
24
     * @var \Jb\Bundle\FileUploaderBundle\Service\ValidatorChain
25
     */
26
    protected $validators;
27
28
    /**
29
     * @var \Jb\Bundle\FileUploaderBundle\Service\EndpointConfiguration
30
     */
31
    protected $configuration;
32
33
    /**
34
     * Constructor
35
     *
36
     * @param \Jb\Bundle\FileUploaderBundle\Service\ValidatorChain $validators
37
     * @param \Jb\Bundle\FileUploaderBundle\Service\EndpointConfiguration $configuration
38
     */
39
    public function __construct(ValidatorChain $validators, EndpointConfiguration $configuration)
40
    {
41
        $this->validators = $validators;
42
        $this->configuration = $configuration;
43
    }
44
45
    /**
46
     * Validate by applying validators from validator chain
47
     *
48
     * @param string $endpoint
49
     * @param mixed $value
50
     * @param string $configKey
51
     *
52
     * @throws \Jb\Bundle\FileUploaderBundle\Exception\ValidationException
53
     */
54
    public function validate($endpoint, $value, $configKey = 'upload_validators')
55
    {
56
        $validationConfiguration = $this->configuration->getValue($endpoint, $configKey);
57
58
        foreach ((array) $validationConfiguration as $validationType => $config) {
59
            $validator = $this->validators->getValidator($validationType);
60
            $validator->applyValidator($value, $config);
61
        }
62
    }
63
}
64