Passed
Push — master ( e66a3e...15c60f )
by Paweł
04:21
created

BookmarkAdmin   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
eloc 38
c 1
b 0
f 1
dl 0
loc 67
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A configureShowFields() 0 8 1
A createQuery() 0 9 1
A configureFormFields() 0 6 1
A configureListFields() 0 14 1
A configureDatagridFilters() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Admin;
6
7
use Doctrine\ORM\QueryBuilder;
8
use Sonata\AdminBundle\Admin\AbstractAdmin;
9
use Sonata\AdminBundle\Datagrid\DatagridMapper;
10
use Sonata\AdminBundle\Datagrid\ListMapper;
11
use Sonata\AdminBundle\Form\FormMapper;
12
use Sonata\AdminBundle\Show\ShowMapper;
13
14
final class BookmarkAdmin extends AbstractAdmin
15
{
16
    protected $datagridValues = [
17
        '_page' => 1,
18
        '_sort_order' => 'DESC',
19
        '_sort_by' => 'created',
20
    ];
21
22
    protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
23
    {
24
        $datagridMapper
25
            ->add('id')
26
            ->add('title')
27
            ->add('timeInSeconds')
28
            ->add('lesson')
29
            ->add('created')
30
            ->add('updated')
31
            ;
32
    }
33
34
    protected function configureListFields(ListMapper $listMapper): void
35
    {
36
        $listMapper
37
            ->add('id')
38
            ->add('title')
39
            ->add('timeInSeconds')
40
            ->add('lesson')
41
            ->add('created')
42
            ->add('updated')
43
            ->add('_action', null, [
44
                'actions' => [
45
                    'show' => [],
46
                    'edit' => [],
47
                    'delete' => [],
48
                ],
49
            ]);
50
    }
51
52
    protected function configureFormFields(FormMapper $formMapper): void
53
    {
54
        $formMapper
55
            ->add('title')
56
            ->add('timeInSeconds')
57
            ->add('lesson')
58
            ;
59
    }
60
61
    protected function configureShowFields(ShowMapper $showMapper): void
62
    {
63
        $showMapper
64
            ->add('id')
65
            ->add('title')
66
            ->add('timeInSeconds')
67
            ->add('created')
68
            ->add('updated')
69
            ;
70
    }
71
72
    public function createQuery($context = 'list')
73
    {
74
        /** @var QueryBuilder $query */
75
        $query = parent::createQuery($context);
76
        $query->andWhere(
77
            $query->expr()->isnull($query->getRootAliases()[0].'.user')
78
        );
79
80
        return  $query;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query returns the type Doctrine\ORM\QueryBuilder which is incompatible with the return type mandated by Sonata\AdminBundle\Admin...nterface::createQuery() of Sonata\AdminBundle\Datagrid\ProxyQueryInterface.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
81
    }
82
}
83