Completed
Pull Request — master (#136)
by
unknown
18:32 queued 09:18
created

PerformanceEventAdmin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 116
Duplicated Lines 12.07 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 14
loc 116
ccs 43
cts 43
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
A configureFormFields() 0 56 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 2
    protected function configureRoutes(RouteCollection $collection)
24
    {
25
        $collection
26 2
            ->add('getVenue')
27 2
            ->add('deletePriceCategories')
28
        ;
29 2
    }
30
31
32
    /**
33
     * @param FormMapper $formMapper
34
     *
35
     * @return void
36
     */
37 1
    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 1
                'dateTime',
44 1
                'sonata_type_datetime_picker',
45
                [
46 1
                    '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 1
            ->add('venue')
53 1
            ->end()
54 1
            ->with('PriceCategory', ['class'=>'col-lg-12'])
55 1
            ->add('priceCategories', 'sonata_type_collection', [
56 1
                'by_reference' => true,
57
                'required' => false,
58
                'cascade_validation' => true,
59
                'type_options'       => [
60
                    'delete' => true,
61
                ],
62
                'label' => false,
63
            ], [
64 1
                'inline'            => 'table',
65 1
                'edit'            => 'inline',
66 1
                'sortable'        => 'position',
67
                'link_parameters'       => [
68 1
                    'performanceEvent_id' => $this->getSubject()->getId(),
69
                ],
70
            ])
71 1
            ->end()
72 1
            ->with('EnableSale', ['class'=>'col-lg-12'])
73 1
            ->add(
74 1
                'setDate',
75 1
                'sonata_type_datetime_picker',
76
                [
77 1
                    'dp_side_by_side'       => true,
78
                    'dp_use_current'        => true,
79
                    'dp_use_seconds'        => false,
80
                    'format' => "dd/MM/yyyy HH:mm",
81
                    'required' => false,
82
                ]
83
            )
84 1
            ->add('setNumber', null, [
85 1
            'required' => false,
86
            ])
87 1
            ->add('enableSale', null, [
88 1
            'required' => false,
89
            ])
90 1
            ->end()
91
        ;
92 1
    }
93
94
    /**
95
     * @param ListMapper $listMapper
96
     *
97
     * @return void
98
     */
99 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...
100
    {
101
        $listMapper
102 2
            ->add('performance')
103 2
            ->add('dateTime')
104 2
            ->add('venue')
105 2
            ->add('_action', 'actions', [
106
                'actions' => [
107
                    'edit' => [],
108
                    'delete' => [],
109 2
                ],
110
            ])
111
        ;
112 2
    }
113
114
    /**
115
     * @param DatagridMapper $datagridMapper
116
     *
117
     * @return void
118
     */
119 2
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
120
    {
121
        $datagridMapper
122 2
            ->add('performance')
123 2
            ->add('venue')
124
        ;
125 2
    }
126
}
127