Completed
Push — master ( 55dbed...4e3396 )
by Piotr
12s
created

Category   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 8
dl 0
loc 76
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 4 1
A getClassName() 0 4 1
B initDataGrid() 0 29 1
A initDataSource() 0 15 1
A initForm() 0 17 1
1
<?php
2
3
namespace FSi\FixturesBundle\Admin;
4
5
use FSi\Bundle\AdminBundle\Doctrine\Admin\CRUDElement;
6
use FSi\Bundle\AdminBundle\Form\TypeSolver;
7
use FSi\Component\DataGrid\DataGridFactoryInterface;
8
use FSi\Component\DataSource\DataSourceFactoryInterface;
9
use Symfony\Component\Form\FormFactoryInterface;
10
11
class Category extends CRUDElement
12
{
13
    public function getId()
14
    {
15
        return 'category';
16
    }
17
18
    public function getClassName()
19
    {
20
        return 'FSi\FixturesBundle\Entity\Category';
21
    }
22
23
    protected function initDataGrid(DataGridFactoryInterface $factory)
24
    {
25
        /* @var $datagrid \FSi\Component\DataGrid\DataGrid */
26
        $datagrid = $factory->createDataGrid('category');
27
        $datagrid->addColumn('title', 'text', [
28
            'label' => 'admin.category.list.title',
29
            'field_mapping' => ['title'],
30
            'editable' => true
31
        ]);
32
        $datagrid->addColumn('actions', 'action', [
33
            'label' => 'admin.category.list.actions',
34
            'field_mapping' => ['id'],
35
            'actions' => [
36
                'news' => [
37
                    'route_name' => "fsi_admin_crud_list",
38
                    'additional_parameters' => ['element' => 'category_news'],
39
                    'parameters_field_mapping' => ['parent' => 'id'],
40
                    'redirect_uri' => false,
41
                ],
42
                'edit' => [
43
                    'route_name' => "fsi_admin_crud_edit",
44
                    'additional_parameters' => ['element' => $this->getId()],
45
                    'parameters_field_mapping' => ['id' => 'id']
46
                ],
47
            ]
48
        ]);
49
50
        return $datagrid;
51
    }
52
53
    protected function initDataSource(DataSourceFactoryInterface $factory)
54
    {
55
        /* @var $datasource \FSi\Component\DataSource\DataSource */
56
        $datasource = $factory->createDataSource('doctrine', ['entity' => $this->getClassName()], 'news');
57
        $datasource->addField('title', 'text', 'like', [
58
            'sortable' => false,
59
            'form_options' => [
60
                'label' => 'admin.category.list.title',
61
            ]
62
        ]);
63
64
        $datasource->setMaxResults(10);
65
66
        return $datasource;
67
    }
68
69
    protected function initForm(FormFactoryInterface $factory, $data = null)
70
    {
71
        $builder = $factory->createNamedBuilder(
72
            'category',
73
            TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\FormType', 'form'),
0 ignored issues
show
Bug introduced by
It seems like \FSi\Bundle\AdminBundle\...ype\\FormType', 'form') targeting FSi\Bundle\AdminBundle\F...peSolver::getFormType() can also be of type object<Symfony\Component\Form\FormTypeInterface>; however, Symfony\Component\Form\F...e::createNamedBuilder() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
74
            $data,
75
            ['data_class' => $this->getClassName()]
76
        );
77
78
        $builder->add(
79
            'title',
80
            TypeSolver::getFormType('Symfony\Component\Form\Extension\Core\Type\TextType', 'text'),
0 ignored issues
show
Bug introduced by
It seems like \FSi\Bundle\AdminBundle\...ype\\TextType', 'text') targeting FSi\Bundle\AdminBundle\F...peSolver::getFormType() can also be of type object<Symfony\Component\Form\FormTypeInterface>; however, Symfony\Component\Form\FormBuilderInterface::add() does only seem to accept string|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
81
            ['label' => 'admin.category.list.title']
82
        );
83
84
        return $builder->getForm();
85
    }
86
}
87