Completed
Pull Request — master (#136)
by
unknown
11:23
created

PerformanceEventAdmin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 99
Duplicated Lines 14.14 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 14
loc 99
ccs 26
cts 26
cp 1
rs 10
c 2
b 0
f 0
wmc 4
lcom 0
cbo 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A configureRoutes() 0 7 1
B configureFormFields() 0 39 1
A configureListFields() 14 14 1
A configureDatagridFilters() 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
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\Route\RouteCollection;
10
11
class PerformanceEventAdmin extends Admin
12
{
13
    protected $baseRouteName = 'AppBundle\Entity\PerformanceEvent';
14
    protected $baseRoutePattern = 'PerformanceEvent';
15
    protected $datagridValues = [
16
        '_sort_order' => 'DESC',
17
        '_sort_by'    => 'dateTime',
18
    ];
19
20
    /**
21
     * @param RouteCollection $collection
22
     */
23
    protected function configureRoutes(RouteCollection $collection)
24
    {
25
        $collection
26 1
            ->add('getVenue')
27
            ->add('deletePriceCategories')
28
        ;
29 1
    }
30 1
31 1
32 1
    /**
33
     * @param FormMapper $formMapper
34 1
     *
35
     * @return void
36
     */
37
    protected function configureFormFields(FormMapper $formMapper)
38
    {
39
        $formMapper
40 1
            ->with('PerformanceEvents', ['class'=>'col-lg-12'])
41 1
            ->add('performance', 'sonata_type_model')
42 1
            ->add(
43
                'dateTime',
44
                'sonata_type_datetime_picker',
45 1
                [
46
                    'dp_side_by_side'       => true,
47
                    'dp_use_current'        => false,
48
                    'dp_use_seconds'        => false,
49
                    'format' => "dd/MM/yyyy HH:mm",
50
                ]
51
            )
52 2
            ->add('venue')
53
            ->end()
54
            ->with('PriceCategory', [
55 2
                'class'=>'col-lg-12',
56 2
            ])
57 2
            ->add('priceCategories', 'sonata_type_collection', [
58 2
                'by_reference' => true,
59
                'required' => false,
60
                'cascade_validation' => true,
61
                'type_options'       => [
62 2
                    'delete' => true,
63
                ],
64
                'label' => false,
65 2
            ], [
66
                'inline'            => 'table',
67
                'edit'            => 'inline',
68
                'sortable'        => 'position',
69
                'link_parameters'       => [
70
                    'performanceEvent_id' => $this->getSubject()->getId(),
71
                ],
72 2
            ])
73
            ->end()
74
        ;
75 2
    }
76 2
77 2
    /**
78 2
     * @param ListMapper $listMapper
79 2
     *
80 2
     * @return void
81
     */
82 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...
83
    {
84
        $listMapper
85
            ->add('performance')
86
            ->add('dateTime')
87
            ->add('venue')
88 2
            ->add('_action', 'actions', [
89
                'actions' => [
90
                    'edit' => [],
91
                    'delete' => [],
92
                ],
93
            ])
94
        ;
95
    }
96
97
    /**
98
     * @param DatagridMapper $datagridMapper
99
     *
100
     * @return void
101
     */
102
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
103
    {
104
        $datagridMapper
105
            ->add('performance')
106
            ->add('venue')
107
        ;
108
    }
109
}
110