Completed
Push — master ( 6c0113...525414 )
by Konstantinos
04:07
created

RoleFormCreator::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
rs 9.4285
cc 1
eloc 8
nc 1
nop 2
1
<?php
2
/**
3
 * This file contains a form creator for Roles
4
 *
5
 * @license    https://github.com/allejo/bzion/blob/master/LICENSE.md GNU General Public License Version 3
6
 */
7
8
namespace BZIon\Form\Creator;
9
10
use BZIon\Form\Type\AdvancedModelType;
11
use BZIon\Form\Type\IpType;
12
use BZIon\Form\Type\ModelType;
13
use Symfony\Component\Validator\Constraints\Length;
14
use Symfony\Component\Validator\Constraints\NotBlank;
15
16
/**
17
 * Form creator for roles
18
 */
19
class RoleFormCreator extends ModelFormCreator
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    protected function build($builder)
25
    {
26
        /** @var \Role $role */
27
        $role = $this->editing;
0 ignored issues
show
Unused Code introduced by
$role is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
28
29
        return $builder
30
            ->add('name', 'text', array(
31
                'constraints' => new NotBlank(),
32
            ))
33
            ->add('display_as_leader', 'checkbox', array(
34
                'required' => false
35
            ))
36
            ->add('display_icon', 'text', array(
37
                'required' => false
38
            ))
39
            ->add('display_color', 'text', array(
40
                'constraints' => new NotBlank(),
41
                'empty_data' => 'green'
42
            ))
43
            ->add('display_name', 'text', array(
44
                'required' => false
45
            ))
46
            ->add('display_order', 'number', array(
47
                'empty_data' => 0
48
            ))
49
            ->add('permissions', new ModelType('Permission', false), array(
50
                'multiple' => true,
51
                'required' => false
52
            ))
53
            ->add('enter', 'submit');
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     * @param \Role $role
59
     */
60
    public function fill($form, $role)
61
    {
62
        $form->get('name')->setData($role->getName());
63
        $form->get('display_as_leader')->setData($role->displayAsLeader());
64
        $form->get('display_icon')->setData($role->getDisplayIcon());
65
        $form->get('display_color')->setData($role->getDisplayColor());
66
        $form->get('display_name')->setData($role->getDisplayName());
67
        $form->get('display_order')->setData($role->getDisplayOrder());
68
        $form->get('permissions')->setData($role->getPermObjects());
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     * @param \Role $role
74
     */
75
    public function update($form, $role)
76
    {
77
        $role->setName($form->get('name')->getData())
78
            ->setDisplayAsLeader($form->get('display_as_leader')->getData())
79
            ->setDisplayIcon($form->get('display_icon')->getData())
80
            ->setDisplayColor($form->get('display_color')->getData())
81
            ->setDisplayName($form->get('display_name')->getData())
82
            ->setDisplayOrder($form->get('display_order')->getData())
83
            ->setPerms($form->get('permissions')->getData());
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function enter($form)
90
    {
91
        $role = \Role::createNewRole(
92
            $form->get('name')->getData(),
93
            true,
94
            $form->get('display_as_leader')->getData(),
95
            $form->get('display_icon')->getData(),
96
            $form->get('display_color')->getData(),
97
            $form->get('display_name')->getData(),
98
            $form->get('display_order')->getData()
99
        );
100
101
        $role->setPerms($form->get('permissions')->getData());
102
103
        return $role;
104
    }
105
}
106