EmailRule::resolve()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 13
cts 13
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 3
crap 2
1
<?php
2
namespace Boekkooi\Bundle\JqueryValidationBundle\Form\Rule\Mapping;
3
4
use Boekkooi\Bundle\JqueryValidationBundle\Exception\LogicException;
5
use Boekkooi\Bundle\JqueryValidationBundle\Form\Rule\ConstraintRule;
6
use Boekkooi\Bundle\JqueryValidationBundle\Form\Rule\ConstraintMapperInterface;
7
use Boekkooi\Bundle\JqueryValidationBundle\Form\RuleCollection;
8
use Boekkooi\Bundle\JqueryValidationBundle\Form\RuleMessage;
9
use Symfony\Component\Form\FormInterface;
10
use Symfony\Component\Validator\Constraint;
11
use Symfony\Component\Validator\Constraints\Email;
12
13
/**
14
 * @author Warnar Boekkooi <[email protected]>
15
 */
16
class EmailRule implements ConstraintMapperInterface
17
{
18
    const RULE_NAME = 'email';
19
20
    /**
21
     * {@inheritdoc}
22
     */
23 3
    public function resolve(Constraint $constraint, FormInterface $form, RuleCollection $collection)
24
    {
25 3
        if (!$this->supports($constraint, $form)) {
26 2
            throw new LogicException();
27
        }
28
29
        /** @var Email $constraint */
30 1
        $collection->set(
31 1
            self::RULE_NAME,
32 1
            new ConstraintRule(
33 1
                self::RULE_NAME,
34 1
                true,
35 1
                new RuleMessage($constraint->message),
36 1
                $constraint->groups
37 1
            )
38 1
        );
39 1
    }
40
41 6
    public function supports(Constraint $constraint, FormInterface $form)
42
    {
43 6
        return get_class($constraint) === Email::class;
44
    }
45
}
46