Completed
Push — master ( 29a9e1...3152e3 )
by Benjamin
14:00 queued 11:53
created

AdminAdmin::preUpdate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Alpixel\Bundle\UserBundle\Admin;
4
5
use FOS\UserBundle\Model\UserManagerInterface;
6
use Sonata\AdminBundle\Admin\Admin;
7
use Sonata\AdminBundle\Datagrid\DatagridMapper;
8
use Sonata\AdminBundle\Datagrid\ListMapper;
9
use Sonata\AdminBundle\Form\FormMapper;
10
11
class AdminAdmin extends Admin
12
{
13
    public function createQuery($context = 'list')
14
    {
15
        $container = $this->getConfigurationPool()->getContainer();
16
        $securityContext = $container->get('security.context');
0 ignored issues
show
Unused Code introduced by
$securityContext 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...
17
18
        $query = parent::createQuery($context);
19
20
        return $query;
21
    }
22
23
    /**
24
     * @param DatagridMapper $datagridMapper
25
     */
26
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
27
    {
28
        $datagridMapper
29
            ->add('id', null, [
30
                'label' => 'ID',
31
            ])
32
            ->add('username', null, [
33
                'label' => 'Nom d\'utilisateur',
34
            ])
35
            ->add('firstname', null, [
36
                'label' => 'Prénom',
37
            ])
38
            ->add('lastname', null, [
39
                'label' => 'Nom',
40
            ])
41
            ->add('email', null, [
42
                'label' => 'Email',
43
            ]);
44
    }
45
46
    /**
47
     * @param ListMapper $listMapper
48
     */
49
    protected function configureListFields(ListMapper $listMapper)
50
    {
51
        $listMapper
52
            ->addIdentifier('id', null, [
53
                'label' => 'ID',
54
            ])
55
            ->addIdentifier('username', null, [
56
                'label' => 'Nom d\'utilisateur',
57
            ])
58
            ->addIdentifier('firstname', null, [
59
                'label' => 'Prénom',
60
            ])
61
            ->addIdentifier('lastname', null, [
62
                'label' => 'Nom',
63
            ])
64
            ->add('email', null, [
65
                'label' => 'Email',
66
            ])
67
            ->add('created', null, [
68
                'label' => 'Date de création',
69
            ])
70
            ->add('lastLogin', null, [
71
                'label' => 'Dernier login',
72
            ]);
73
    }
74
75
    /**
76
     * @param FormMapper $formMapper
77
     */
78
    protected function configureFormFields(FormMapper $formMapper)
79
    {
80
        $container = $this->getConfigurationPool()->getContainer();
81
        $securityContext = $container->get('security.context');
0 ignored issues
show
Unused Code introduced by
$securityContext 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...
82
83
        $roles = [
84
            'ROLE_USER'  => 'Simple utilisateur',
85
            'ROLE_ADMIN' => 'Administrateur',
86
        ];
87
88
        $formMapper
89
            ->with('Informations personnelles', [
90
                'description' => '',
91
                'class'       => 'col-md-8',
92
            ])
93
                ->add('username', null, [
94
                    'label' => 'Nom d\'utilisateur',
95
                ])
96
                ->add('email', null, [
97
                    'label' => 'Email',
98
                ])
99
                ->add('firstname', null, [
100
                    'label' => 'Prénom',
101
                ])
102
                ->add('lastname', null, [
103
                    'label' => 'Nom',
104
                ])
105
            ->end()
106
            ->with('Paramétrage', [
107
                'description' => '',
108
                'class'       => 'col-md-4',
109
            ])
110
                ->add('enabled', null, [
111
                    'label' => 'Compte actif',
112
                ])
113
                ->add('roles', 'choice', [
114
                    'multiple'  => true,
115
                    'choices'   => $roles,
116
                    'label'     => 'Permissions',
117
                ])
118
                ->add('plainPassword', 'text', [
119
                    'label'     => 'Changer le mot de passe',
120
                    'required'  => false,
121
                ])
122
            ->end();
123
    }
124
125
    public function preUpdate($user)
126
    {
127
        $this->getUserManager()->updateUser($user);
128
    }
129
130
    public function setUserManager(UserManagerInterface $userManager)
131
    {
132
        $this->userManager = $userManager;
133
    }
134
135
    /**
136
     * @return UserManagerInterface
137
     */
138
    public function getUserManager()
139
    {
140
        return $this->userManager;
141
    }
142
}
143