ConstraintMappingPass   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 34
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 21 4
A addMapper() 0 4 1
1
<?php
2
namespace Boekkooi\Bundle\JqueryValidationBundle\Form\Rule\Processor;
3
4
use Boekkooi\Bundle\JqueryValidationBundle\Form\FormRuleContextBuilder;
5
use Boekkooi\Bundle\JqueryValidationBundle\Form\FormRuleProcessorInterface;
6
use Boekkooi\Bundle\JqueryValidationBundle\Form\Rule\ConstraintMapperInterface;
7
use Boekkooi\Bundle\JqueryValidationBundle\Form\RuleCollection;
8
use Boekkooi\Bundle\JqueryValidationBundle\Form\FormRuleProcessorContext;
9
10
/**
11
 * @author Warnar Boekkooi <[email protected]>
12
 */
13
class ConstraintMappingPass implements FormRuleProcessorInterface
14
{
15
    /**
16
     * @var ConstraintMapperInterface[]
17
     */
18
    protected $mappers = array();
19
20
    public function process(FormRuleProcessorContext $processContext, FormRuleContextBuilder $formRuleContext)
21
    {
22
        $constraints = $processContext->getConstraints();
23
        $form = $processContext->getForm();
24
25
        $collection = new RuleCollection();
26
        foreach ($this->mappers as $mapper) {
27
            foreach ($constraints as $constraint) {
28
                if (!$mapper->supports($constraint, $form)) {
29
                    continue;
30
                }
31
32
                $mapper->resolve($constraint, $form, $collection);
33
            }
34
        }
35
36
        $formRuleContext->add(
37
            $processContext->getView(),
38
            $collection
39
        );
40
    }
41
42
    public function addMapper(ConstraintMapperInterface $mapper)
43
    {
44
        $this->mappers[] = $mapper;
45
    }
46
}
47