RoleAdmin   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 76
Duplicated Lines 23.68 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 76%

Importance

Changes 0
Metric Value
dl 18
loc 76
ccs 19
cts 25
cp 0.76
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 5

4 Methods

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