Completed
Pull Request — master (#120)
by Serhii
18:46
created

PerformanceAdmin::configureFormFields()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 85
Code Lines 57

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 39
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 57
nc 1
nop 1
dl 0
loc 85
rs 8.6875
c 0
b 0
f 0
ccs 39
cts 39
cp 1
crap 1

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\Show\ShowMapper;
10
11
class PerformanceAdmin extends Admin
12
{
13
    protected $baseRouteName = 'AppBundle\Entity\Performance';
14
    protected $baseRoutePattern = 'Performance';
15
    protected $datagridValues = [
16
        '_sort_order' => 'DESC',
17
        '_sort_by'    => 'premiere',
18
    ];
19
20
    /**
21
     * @param \Sonata\AdminBundle\Show\ShowMapper $showMapper
22
     *
23
     * @return void
24
     */
25
    protected function configureShowFields(ShowMapper $showMapper)
26
    {
27
        $showMapper
28
            ->add('title')
29
            ->add('type')
30
            ->add('description')
31
            ->add('premiere')
32
            ->add('performanceEvents')
33
            ->add('roles')
34
        ;
35
    }
36
37
    /**
38
     * @param \Sonata\AdminBundle\Form\FormMapper $formMapper
39
     *
40
     * @return void
41
     */
42 1
    protected function configureFormFields(FormMapper $formMapper)
43
    {
44 1
        $em = $this->modelManager->getEntityManager('AppBundle\Entity\History');
45
46 1
        $query = $em->createQueryBuilder('h')
47 1
            ->select('h')
48 1
            ->from('AppBundle:History', 'h')
49 1
            ->where('h.type = :type')
50 1
            ->orderBy('h.createdAt', 'ASC')
51 1
            ->setParameter('type', 'festival');
52
53
        $formMapper
54 1
            ->add('title')
55 1
            ->add('type')
56 1
            ->add('festival', 'sonata_type_model', [
57 1
                'required' => false,
58 1
                'query' => $query,
59
            ])
60 1
            ->add('description', null, ['attr' => ['class' => 'wysihtml5', 'style' => 'height: 200px']])
61 1
            ->add(
62 1
                'mainPicture',
63 1
                'sonata_type_model_list',
64 1
                ['required' => false],
65
                [
66
                    'link_parameters' => [
67
                        'context'  => 'performance',
68
                        'provider' => 'sonata.media.provider.image',
69 1
                    ],
70
                ]
71
            )
72 1
            ->add(
73 1
                'sliderImage',
74 1
                'sonata_type_model_list',
75 1
                ['required' => false],
76
                [
77
                    'link_parameters' => [
78
                        'context'  => 'slider',
79
                        'provider' => 'sonata.media.provider.image',
80 1
                    ],
81
                ]
82
            )
83 1
            ->add(
84 1
                'premiere',
85 1
                'sonata_type_datetime_picker',
86
                [
87 1
                    'dp_side_by_side'       => true,
88
                    'dp_use_current'        => false,
89
                    'dp_use_seconds'        => false,
90
                    'format' => "dd/MM/yyyy HH:mm",
91
                ]
92
            )
93 1
            ->add(
94 1
                'roles',
95 1
                'sonata_type_collection',
96
                [
97 1
                    'required' => false,
98
                    'by_reference' => false,
99
                ],
100
                [
101 1
                    'edit' => 'inline',
102
                    'inline' => 'table',
103
                    'sortable'  => 'position',
104
                ]
105
            )
106 1
            ->add(
107 1
                'galleryHasMedia',
108 1
                'sonata_type_collection',
109
                [
110 1
                    'required' => false,
111
                    'label' => 'Gallery',
112
                ],
113
                [
114 1
                    'edit' => 'inline',
115
                    'inline' => 'table',
116
                    'sortable'  => 'position',
117
                    'targetEntity' => 'Application\Sonata\MediaBundle\Entity\GalleryHasMedia',
118
                    'admin_code' => 'sonata.media.admin.gallery_has_media',
119
                    'link_parameters' => [
120
                        'context'  => 'performance',
121
                        'provider' => 'sonata.media.provider.image',
122
                    ],
123
                ]
124
            )
125
        ;
126 1
    }
127
128
    /**
129
     * @param \Sonata\AdminBundle\Datagrid\ListMapper $listMapper
130
     *
131
     * @return void
132
     */
133 2
    protected function configureListFields(ListMapper $listMapper)
134
    {
135
        $listMapper
136 2
            ->add('mainPicture', 'string', ['template' => '::SonataAdmin/thumbnail.html.twig'])
137 2
            ->addIdentifier('title')
138 2
            ->add('type')
139 2
            ->add('premiere')
140 2
            ->add('festival')
141
        ;
142 2
    }
143
144
    /**
145
     * @param \Sonata\AdminBundle\Datagrid\DatagridMapper $datagridMapper
146
     *
147
     * @return void
148
     */
149 2
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
150
    {
151
        $datagridMapper
152 2
            ->add('title')
153 2
            ->add('type')
154 2
            ->add('festival')
155
        ;
156 2
    }
157
}
158