Completed
Push — master ( c37a1b...043479 )
by Serhii
11s
created

PriceCategoryAdmin   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 20 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 12
loc 60
rs 10
wmc 5
lcom 0
cbo 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A configureFormFields() 0 8 1
A configureListFields() 12 12 1
A configureDatagridFilters() 0 6 1
A toString() 0 6 2

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 AppBundle\Entity\PriceCategory;
6
use Sonata\AdminBundle\Admin\Admin;
7
use Sonata\AdminBundle\Datagrid\ListMapper;
8
use Sonata\AdminBundle\Datagrid\DatagridMapper;
9
use Sonata\AdminBundle\Form\FormMapper;
10
11
class PriceCategoryAdmin extends Admin
12
{
13
    protected $baseRouteName = 'AppBundle\Entity\PriceCategory';
14
    protected $baseRoutePattern = 'PriceCategory';
15
    protected $datagridValues = [
16
        '_sort_order' => 'DESC',
17
        '_sort_by'    => 'venue',
18
    ];
19
20
    /**
21
     * @param \Sonata\AdminBundle\Form\FormMapper $formMapper
22
     *
23
     * @return void
24
     */
25
    protected function configureFormFields(FormMapper $formMapper)
26
    {
27
        $formMapper
28
            ->add('title')
29
            ->add('color', 'sonata_type_color_selector')
30
            ->add('venue')
31
        ;
32
    }
33
34
    /**
35
     * @param \Sonata\AdminBundle\Datagrid\ListMapper $listMapper
36
     *
37
     * @return void
38
     */
39 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...
40
    {
41
        $listMapper
42
            ->add('venue')
43
            ->add('_action', 'actions', [
44
                'actions' => [
45
                    'edit' => [],
46
                    'delete' => [],
47
                ],
48
            ])
49
        ;
50
    }
51
52
    /**
53
     * @param \Sonata\AdminBundle\Datagrid\DatagridMapper $datagridMapper
54
     *
55
     * @return void
56
     */
57
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
58
    {
59
        $datagridMapper
60
            ->add('venue')
61
        ;
62
    }
63
64
    public function toString($object)
65
    {
66
        return $object instanceof PriceCategory
67
            ? $object->getTitle()
68
            : 'PriceCategory'; // shown in the breadcrumb on the create views
69
    }
70
}
71