Completed
Pull Request — master (#144)
by Serhii
24:57
created

UserAdmin   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 93.55%

Importance

Changes 2
Bugs 2 Features 0
Metric Value
c 2
b 2
f 0
dl 0
loc 83
ccs 29
cts 31
cp 0.9355
rs 10
wmc 5
lcom 1
cbo 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A configureFormFields() 0 11 1
A createQuery() 0 14 1
A configureListFields() 0 15 1
A configureDatagridFilters() 0 6 1
A __toString() 0 4 1
1
<?php
2
3
namespace AppBundle\Admin;
4
5
use AppBundle\Entity\User;
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
use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery;
11
12
class UserAdmin extends Admin
13
{
14
    protected $baseRouteName = 'AppBundle\Entity\User';
15
    protected $baseRoutePattern = 'User';
16
    protected $datagridValues = [
17
        '_sort_order' => 'DESC',
18
        '_sort_by' => 'id',
19
    ];
20
21
    /**
22
     * @param \Sonata\AdminBundle\Form\FormMapper $formMapper
23
     */
24 1
    protected function configureFormFields(FormMapper $formMapper)
25
    {
26
        $formMapper
27 1
            ->with('User', ['class' => 'col-lg-12'])
28 1
            ->add('firstName')
29 1
            ->add('lastName')
30 1
            ->add('email')
31 1
            ->add('orders')
32 1
           ->end()
33
        ;
34 1
    }
35
36
    /**
37
     * {@inheritdoc} annotation.
38
     *
39
     * @param string $context = 'list'
40
     *
41
     * @return \Sonata\AdminBundle\Datagrid\ProxyQueryInterface|ProxyQuery
42
     */
43 3
    public function createQuery($context = 'list')
44
    {
45 3
        $em = $this->modelManager->getEntityManager('AppBundle:User');
46
        $queryBuilder = $em
47 3
            ->createQueryBuilder('u')
48 3
            ->select('u')
49 3
            ->from('AppBundle:User', 'u')
50 3
            ->where('u.email IS NOT NULL ')
51 3
            ->andWhere('u.role = :param')
52 3
        ->setParameter('param', 'ROLE_API');
53 3
        $query = new ProxyQuery($queryBuilder);
54
55 3
        return $query;
56
    }
57
58
    /**
59
     * @param \Sonata\AdminBundle\Datagrid\ListMapper $listMapper
60
     */
61 3
    protected function configureListFields(ListMapper $listMapper)
62
    {
63
        $listMapper
64 3
            ->add('email')
65 3
            ->add('firstName')
66 3
            ->add('lastName')
67 3
            ->add('orders')
68 3
            ->add('_action', 'actions', [
69 3
                'actions' => [
70
                    'edit' => [],
71
                    'delete' => [],
72
                ],
73
            ])
74
        ;
75 3
    }
76
77
    /**
78
     * @param \Sonata\AdminBundle\Datagrid\DatagridMapper $datagridMapper
79
     */
80 3
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
81
    {
82
        $datagridMapper
83 3
            ->add('email')
84
        ;
85 3
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function __toString()
91
    {
92
        return (string) $this->getEmail();
0 ignored issues
show
Bug introduced by
The method getEmail() does not seem to exist on object<AppBundle\Admin\UserAdmin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
93
    }
94
}
95