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

PerformanceEventAdmin::configureFormFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 56
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 28
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 41
nc 1
nop 1
dl 0
loc 56
ccs 28
cts 28
cp 1
crap 1
rs 9.7251
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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