Test Setup Failed
Push — master ( f71949...6c6bd7 )
by Julito
55:21
created

UserGroupAdmin   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 28.38 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 21
loc 74
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
B configureFormFields() 21 25 1
A preUpdate() 0 4 1
A configureShowField() 0 7 1
A configureDatagridFilters() 0 7 1
A configureListFields() 0 7 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
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Admin;
5
6
use Sonata\AdminBundle\Admin\AbstractAdmin;
7
use Sonata\AdminBundle\Form\FormMapper;
8
use Sonata\AdminBundle\Datagrid\DatagridMapper;
9
use Sonata\AdminBundle\Datagrid\ListMapper;
10
use Sonata\AdminBundle\Show\ShowMapper;
11
use Chamilo\CoreBundle\Entity\Course;
12
13
14
/**
15
 * Class UserGroupAdmin
16
 * @package Chamilo\CoreBundle\Admin
17
 */
18
class UserGroupAdmin extends AbstractAdmin
19
{
20
    /**
21
     * @param FormMapper $formMapper
22
     */
23 View Code Duplication
    protected function configureFormFields(FormMapper $formMapper)
24
    {
25
        $formMapper
26
            ->add('name')
27
            ->add('description', 'ckeditor')
28
            ->add(
29
                'users',
30
                'sonata_type_collection',
31
                array(
32
                    'cascade_validation' => true,
33
                ),
34
                array(
35
                    // 'allow_delete' => true,
36
                    'by_reference' => false,
37
                    'edit' => 'inline',
38
                    'inline' => 'table',
39
                    //'btn_add' => true,
40
                    //'multiple' => true
41
                    //'sortable'          => 'position',
42
                    //'link_parameters'   => array('content' => $users),
43
                    'admin_code' => 'sonata.admin.user_group_rel_user',
44
                )
45
            )
46
        ;
47
    }
48
49
    /**
50
     * Very important in order to save the related entities!
51
     * @param Course $userGroup
52
     * @return mixed|void
53
     */
54
    public function preUpdate($userGroup)
55
    {
56
        //$userGroup->setUsers($userGroup->getUsers());
57
    }
58
59
    /**
60
     * @param ShowMapper $showMapper
61
     */
62
    protected function configureShowField(ShowMapper $showMapper)
63
    {
64
        $showMapper
65
            ->add('id', 'text', array('label' => 'Usergroup'))
66
            ->add('name')
67
        ;
68
    }
69
70
    /**
71
     * @param DatagridMapper $datagridMapper
72
     */
73
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
74
    {
75
        $datagridMapper
76
            ->add('id')
77
            ->add('name')
78
        ;
79
    }
80
81
    /**
82
     * @param ListMapper $listMapper
83
     */
84
    protected function configureListFields(ListMapper $listMapper)
85
    {
86
        $listMapper
87
            ->addIdentifier('id')
88
            ->addIdentifier('name')
89
        ;
90
    }
91
}
92