HistoryAdmin   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 100
Duplicated Lines 17 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 17
loc 100
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configureFormFields() 0 51 1
A configureDatagridFilters() 0 6 1
A configureListFields() 17 17 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 App\Entity\History;
6
use FOS\CKEditorBundle\Form\Type\CKEditorType;
7
use Sonata\AdminBundle\Admin\AbstractAdmin;
8
use Sonata\AdminBundle\Datagrid\ListMapper;
9
use Sonata\AdminBundle\Datagrid\DatagridMapper;
10
use Sonata\AdminBundle\Form\FormMapper;
11
use Sonata\AdminBundle\Form\Type\ModelListType;
12
use Sonata\Form\Type\CollectionType;
13
use Sonata\Form\Type\DateTimePickerType;
14
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
15
16
class HistoryAdmin extends AbstractAdmin
17
{
18
    protected $baseRouteName = 'App\Entity\History';
19
    protected $baseRoutePattern = 'History';
20
    protected $datagridValues = [
21
        '_sort_order' => 'ASC',
22
        '_sort_by' => 'name',
23
    ];
24
25
    /**
26
     * @param \Sonata\AdminBundle\Form\FormMapper $formMapper
27
     *
28
     * @return void
29
     */
30 2
    protected function configureFormFields(FormMapper $formMapper)
31
    {
32
        $formMapper
33 2
            ->add('title')
34 2
            ->add('type', ChoiceType::class, [
35 2
                'choices'  => History::getTypes()
36
            ])
37 2
            ->add('dateTime', DateTimePickerType::class,
38
                [
39 2
                    'label' => 'History_Date',
40
                    'widget' => 'single_text',
41
                    'format' => 'yyyy'
42
                ]
43
            )
44 2
            ->add('text', CKEditorType::class,
45
                [
46
                    'attr' => [
47 2
                            'class' => 'wysihtml5',
48
                            'style' => 'height:300px',
49
                    ],
50
                ]
51
            )
52 2
            ->add('mainPicture', ModelListType::class,
53
                [
54 2
                    'required' => false,
55
                    'btn_list' => false,
56
                ], [
57
                    'link_parameters' => [
58 2
                        'context' => 'history',
59
                        'provider' => 'sonata.media.provider.image',
60
                    ],
61
                ]
62
            )
63 2
            ->add('galleryHasMedia', CollectionType::class,
64
                [
65 2
                    'required' => false,
66
                    'label' => 'Gallery'
67
                ], [
68 2
                    'edit' => 'inline',
69
                    'inline' => 'table',
70
                    'sortable'  => 'position',
71
                    'targetEntity' => 'App\Entity\GalleryHasMedia',
72
                    'admin_code' => 'sonata.media.admin.gallery_has_media',
73
                    'link_parameters' => [
74
                        'context'  => 'history',
75
                        'provider' => 'sonata.media.provider.image',
76
                    ],
77
                ]
78
            )
79
        ;
80 2
    }
81
    /**
82
     * @param \Sonata\AdminBundle\Datagrid\ListMapper $listMapper
83
     *
84
     * @return void
85
     */
86 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...
87
    {
88
        $listMapper
89 2
            ->add('mainPicture', 'string', ['template' => 'bundles/SonataAdmin/thumbnail.html.twig'])
90 2
            ->add('year', null, ['label' => 'History_Date'])
91 2
            ->addIdentifier('title')
92 2
            ->add('type')
93 2
            ->add('_action', 'actions',
94
                [
95
                    'actions' => [
96 2
                        'edit' => [],
97
                        'delete' => [],
98
                    ],
99
                ]
100
            )
101
        ;
102 2
    }
103
104
    /**
105
     * @param \Sonata\AdminBundle\Datagrid\DatagridMapper $datagridMapper
106
     *
107
     * @return void
108
     */
109 2
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
110
    {
111
        $datagridMapper
112 2
            ->add('title')
113 2
            ->add('dateTime');
114 2
    }
115
}
116