RuleAdmin::configureShowFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 10
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\CoreBundle\Admin;
6
7
use A2lix\TranslationFormBundle\Form\Type\TranslationsType;
8
use FOS\CKEditorBundle\Form\Type\CKEditorType;
0 ignored issues
show
Bug introduced by
The type FOS\CKEditorBundle\Form\Type\CKEditorType was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Sonata\AdminBundle\Admin\AbstractAdmin;
10
use Sonata\AdminBundle\Datagrid\DatagridMapper;
11
use Sonata\AdminBundle\Datagrid\ListMapper;
12
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
13
use Sonata\AdminBundle\Form\FormMapper;
14
use Sonata\AdminBundle\Form\Type\ModelListType;
15
use Sonata\AdminBundle\Route\RouteCollectionInterface;
16
use Sonata\AdminBundle\Show\ShowMapper;
17
use Symfony\Component\Form\Extension\Core\Type\TextType;
18
use VideoGamesRecords\CoreBundle\Form\Type\RichTextEditorType;
19
20
class RuleAdmin extends AbstractAdmin
21
{
22
    protected $baseRouteName = 'vgrcorebundle_admin_rule';
23
24
    /**
25
     * @param RouteCollectionInterface $collection
26
     */
27
    protected function configureRoutes(RouteCollectionInterface $collection): void
28
    {
29
        $collection
30
            ->remove('export');
31
    }
32
33
    /**
34
     * @param ProxyQueryInterface $query
35
     * @return ProxyQueryInterface
36
     */
37
    protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface
38
    {
39
        $query = parent::configureQuery($query);
40
        $query->leftJoin($query->getRootAliases()[0] . '.translations', 't')
0 ignored issues
show
Bug introduced by
The method leftJoin() does not exist on Sonata\AdminBundle\Datagrid\ProxyQueryInterface. It seems like you code against a sub-type of Sonata\AdminBundle\Datagrid\ProxyQueryInterface such as Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
        $query->/** @scrutinizer ignore-call */ 
41
                leftJoin($query->getRootAliases()[0] . '.translations', 't')
Loading history...
Bug introduced by
The method getRootAliases() does not exist on Sonata\AdminBundle\Datagrid\ProxyQueryInterface. It seems like you code against a sub-type of Sonata\AdminBundle\Datagrid\ProxyQueryInterface such as Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
        $query->leftJoin($query->/** @scrutinizer ignore-call */ getRootAliases()[0] . '.translations', 't')
Loading history...
41
            ->addSelect('t');
42
        return $query;
43
    }
44
45
    /**
46
     * @param FormMapper $form
47
     */
48
    protected function configureFormFields(FormMapper $form): void
49
    {
50
        $form
51
            ->add('name', TextType::class, [
52
                'label' => 'rule.form.name',
53
                'required' => true,
54
            ])
55
            ->add(
56
                'player',
57
                ModelListType::class,
58
                [
59
                    'data_class' => null,
60
                    'btn_add' => false,
61
                    'btn_list' => true,
62
                    'btn_edit' => false,
63
                    'btn_delete' => false,
64
                    'btn_catalogue' => true,
65
                    'label' => 'rule.form.player',
66
                ]
67
            )
68
            ->add('translations', TranslationsType::class, [
69
                'label' => 'rule.form.translations',
70
                'fields' => [
71
                    'content' => [
72
                        'field_type' => RichTextEditorType::class,
73
                        'label' => 'rule.form.rules',
74
                        'required' => false,
75
                     ]
76
                ]
77
            ]);
78
    }
79
80
    /**
81
     * @param DatagridMapper $filter
82
     */
83
    protected function configureDatagridFilters(DatagridMapper $filter): void
84
    {
85
        $filter
86
            ->add('id', null, ['label' => 'rule.filter.id'])
87
            ->add('name', null, ['label' => 'rule.filter.name']);
88
    }
89
90
    /**
91
     * @param ListMapper $list
92
     */
93
    protected function configureListFields(ListMapper $list): void
94
    {
95
        $list
96
            ->addIdentifier('id', null, ['label' => 'rule.list.id'])
97
            ->add('name', null, ['label' => 'rule.list.name'])
98
            ->add('player', null, [
99
                'associated_property' => 'pseudo',
100
                'label' => 'rule.list.player',
101
            ])
102
            ->add('created_at', 'datetime', ['label' => 'rule.list.createdAt'])
103
            ->add('updated_at', 'datetime', ['label' => 'rule.list.updatedAt'])
104
            ->add('_action', 'actions', [
105
                'actions' => [
106
                    'show' => [],
107
                    'edit' => [],
108
                ]
109
            ]);
110
    }
111
112
    /**
113
     * @param ShowMapper $show
114
     */
115
    protected function configureShowFields(ShowMapper $show): void
116
    {
117
        $show
118
            ->add('id', null, ['label' => 'rule.show.id'])
119
            ->add('name', null, ['label' => 'rule.show.name'])
120
            ->add('player', null, ['label' => 'rule.show.player'])
121
            ->add('created_at', 'datetime', ['label' => 'rule.show.createdAt'])
122
            ->add('updated_at', 'datetime', ['label' => 'rule.show.updatedAt'])
123
            ->add('games', null, ['label' => 'rule.show.games'])
124
            ->add('getContent', null, ['label' => 'rule.show.text', 'safe' => true]);
125
    }
126
}
127