ViewTransformerProcessor   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 29
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A findTransformer() 0 11 3
A getFormRuleMessage() 0 14 3
1
<?php
2
namespace Boekkooi\Bundle\JqueryValidationBundle\Form\Rule\Processor;
3
4
use Boekkooi\Bundle\JqueryValidationBundle\Form\FormRuleProcessorInterface;
5
use Boekkooi\Bundle\JqueryValidationBundle\Form\RuleMessage;
6
use Symfony\Component\Form\FormConfigInterface;
7
8
/**
9
 * @author Warnar Boekkooi <[email protected]>
10
 */
11
abstract class ViewTransformerProcessor implements FormRuleProcessorInterface
12
{
13
    protected function findTransformer(FormConfigInterface $config, $class)
14
    {
15
        $transformers = $config->getViewTransformers();
16
        foreach ($transformers as $transformer) {
17
            if (get_class($transformer) === $class) {
18
                return $transformer;
19
            }
20
        }
21
22
        return null;
23
    }
24
25
    protected function getFormRuleMessage(FormConfigInterface $config)
26
    {
27
        // Get correct error message if one is set.
28
        if ($config->hasOption('invalid_message')) {
29
            $params = $config->getOption('invalid_message_parameters');
30
31
            return new RuleMessage(
32
                $config->getOption('invalid_message'),
33
                is_array($params) ? $params : array()
34
            );
35
        }
36
37
        return null;
38
    }
39
}
40