CreditcardRule   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 31
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 18 2
A supports() 0 4 1
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\CardScheme;
12
13
/**
14
 * @author Warnar Boekkooi <[email protected]>
15
 */
16
class CreditcardRule implements ConstraintMapperInterface
17
{
18
    const RULE_NAME = 'creditcard';
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 CardScheme $constraint */
30
        // TODO support schemes
31 1
        $collection->set(
32 1
            self::RULE_NAME,
33 1
            new ConstraintRule(
34 1
                self::RULE_NAME,
35 1
                true,
36 1
                new RuleMessage($constraint->message),
37 1
                $constraint->groups
38 1
            )
39 1
        );
40 1
    }
41
42 6
    public function supports(Constraint $constraint, FormInterface $form)
43
    {
44 6
        return get_class($constraint) === CardScheme::class;
45
    }
46
}
47