Completed
Pull Request — master (#162)
by
unknown
03:18
created

RoleAdmin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 78
Duplicated Lines 23.08 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
dl 18
loc 78
ccs 21
cts 27
cp 0.7778
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A configureFormFields() 0 7 1
A configureListFields() 18 20 1
A configureDatagridFilters() 0 9 1
A configureShowFields() 0 9 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 AppBundle\Admin;
4
5
use Sonata\AdminBundle\Admin\Admin;
6
use Sonata\AdminBundle\Datagrid\ListMapper;
7
use Sonata\AdminBundle\Datagrid\DatagridMapper;
8
use Sonata\AdminBundle\Form\FormMapper;
9
use Sonata\AdminBundle\Show\ShowMapper;
10
use AppBundle\Entity\Role;
11
12
class RoleAdmin extends Admin
13
{
14
    protected $baseRouteName = 'AppBundle\Entity\Role';
15
    protected $baseRoutePattern = 'Role';
16
    protected $datagridValues = [
17
        '_sort_order' => 'ASC',
18
        '_sort_by'    => 'name',
19
    ];
20
21
    /**
22
     * @param \Sonata\AdminBundle\Show\ShowMapper $showMapper
23
     *
24
     * @return void
25
     */
26
    protected function configureShowFields(ShowMapper $showMapper)
27
    {
28
        $showMapper
29
            ->add('title')
30
            ->add('description')
31
            ->add('performance')
32
            ->add('employee')
33
        ;
34
    }
35
36
    /**
37
     * @param \Sonata\AdminBundle\Form\FormMapper $formMapper
38
     *
39
     * @return void
40
     */
41 1
    protected function configureFormFields(FormMapper $formMapper)
42
    {
43
        $formMapper
44 1
            ->add('title')
45 1
            ->add('description', null, ['required' => false])
46 1
            ->add('employee', 'sonata_type_model', ['required' => false]);
47 1
    }
48
49
    /**
50
     * @param \Sonata\AdminBundle\Datagrid\ListMapper $listMapper
51
     *
52
     * @return void
53
     */
54 2 View Code Duplication
    protected function configureListFields(ListMapper $listMapper)
0 ignored issues
show
Duplication introduced by
This method 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...
55
    {
56
        $listMapper
57 2
            ->addIdentifier('title')
58 2
            ->add('description')
59 2
            ->add('performance')
60 2
            ->add('employee')
61 2
            ->add(
62 2
                '_action',
63 2
                'actions',
64
                [
65 2
                    'actions' => [
66
                        'show' => [],
67
                        'edit' => [],
68
                        'delete' => [],
69
                    ],
70
                ]
71
            )
72
        ;
73 2
    }
74
75
    /**
76
     * @param \Sonata\AdminBundle\Datagrid\DatagridMapper $datagridMapper
77
     *
78
     * @return void
79
     */
80 2
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
81
    {
82
        $datagridMapper
83 2
            ->add('title')
84 2
            ->add('description')
85 2
            ->add('performance')
86 2
            ->add('employee')
87
        ;
88 2
    }
89
}
90