ValidationGroupsTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 55
loc 55
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setValidationGroups() 4 4 1
A addValidationGroup() 9 9 2
A hasValidationGroup() 4 4 1
A getValidationGroups() 4 4 1
A removeValidationGroups() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace steevanb\SymfonyFormOptionsBuilder\Behavior;
4
5 View Code Duplication
trait ValidationGroupsTrait
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6
{
7
    use OptionAccessorsTrait;
8
9
    /**
10
     * @param null|false|array|\Closure $groups
11
     * @return $this
12
     * @link http://symfony.com/doc/current/reference/forms/types/submit.html#validation-groups
13
     */
14
    public function setValidationGroups($groups)
15
    {
16
        return $this->setOption('validation_groups', $groups);
17
    }
18
19
    /**
20
     * @param null|false|array|\Closure $group
21
     * @return $this
22
     */
23
    public function addValidationGroup($group)
24
    {
25
        $groups = $this->getValidationGroups();
26
        if (in_array($group, $groups) === false) {
27
            $groups[] = $group;
28
        }
29
30
        return $this->setValidationGroups($groups);
31
    }
32
33
    /**
34
     * @param string $group
35
     * @return bool
36
     * @link http://symfony.com/doc/current/reference/forms/types/submit.html#validation-groups
37
     */
38
    public function hasValidationGroup($group)
39
    {
40
        return in_array($group, $this->getValidationGroups());
41
    }
42
43
    /**
44
     * @return null|false|array|\Closure
45
     * @link http://symfony.com/doc/current/reference/forms/types/submit.html#validation-groups
46
     */
47
    public function getValidationGroups()
48
    {
49
        return $this->getOption('validation_groups');
50
    }
51
52
    /**
53
     * @return $this
54
     */
55
    public function removeValidationGroups()
56
    {
57
        return $this->removeOption('validation_groups');
58
    }
59
}
60