GroupNullResolverPass   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
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 26
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B compile() 0 20 6
1
<?php
2
namespace Boekkooi\Bundle\JqueryValidationBundle\Form\Rule\Compiler;
3
4
use Boekkooi\Bundle\JqueryValidationBundle\Form\FormRuleCompilerInterface;
5
use Boekkooi\Bundle\JqueryValidationBundle\Form\FormRuleContextBuilder;
6
use Symfony\Component\PropertyAccess\PropertyPath;
7
8
/**
9
 * @author Warnar Boekkooi <[email protected]>
10
 */
11
class GroupNullResolverPass implements FormRuleCompilerInterface
12
{
13
    /**
14
     * @param FormRuleContextBuilder $context
15
     */
16
    public function compile(FormRuleContextBuilder $context)
17
    {
18
        $formGroups = $context->getGroups();
19
        foreach ($formGroups as $name => $groups) {
20
            if ($groups !== null) {
21
                continue;
22
            }
23
24
            // Find the closest validation group
25
            $path = new PropertyPath($name);
26
            do {
27
                $parentName = (string) $path;
28
                if (isset($formGroups[$parentName]) && ($groups = $formGroups[$parentName]) !== null) {
29
                    $context->addGroup($name, $groups);
30
                    break;
31
                }
32
                $path = $path->getParent();
33
            } while ($path !== null);
34
        }
35
    }
36
}
37