IbanRule   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A resolve() 0 17 2
A supports() 0 4 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\RuleCollection;
7
use Boekkooi\Bundle\JqueryValidationBundle\Form\Rule\ConstraintMapperInterface;
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\Iban;
12
13
/**
14
 * @author Warnar Boekkooi <[email protected]>
15
 */
16
class IbanRule implements ConstraintMapperInterface
17
{
18
    const RULE_NAME = 'iban';
19
20
    /**
21
     * @var bool
22
     */
23
    private $active;
24
25 7
    public function __construct($active)
26
    {
27 7
        $this->active = $active;
28 7
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 3
    public function resolve(Constraint $constraint, FormInterface $form, RuleCollection $collection)
34
    {
35 3
        if (!$this->supports($constraint, $form)) {
36 2
            throw new LogicException();
37
        }
38
39
        /** @var Iban $constraint */
40 1
        $collection->set(
41 1
            self::RULE_NAME,
42 1
            new ConstraintRule(
43 1
                self::RULE_NAME,
44 1
                true,
45 1
                new RuleMessage($constraint->message),
46 1
                $constraint->groups
47 1
            )
48 1
        );
49 1
    }
50
51 7
    public function supports(Constraint $constraint, FormInterface $form)
52
    {
53 7
        return $this->active && get_class($constraint) === Iban::class;
54
    }
55
}
56