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

News::initDataSource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 4
nc 1
nop 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 FSi\FixturesBundle\DataGrid\NewsDataGridBuilder;
10
use FSi\FixturesBundle\DataSource\NewsDataSourceBuilder;
11
use FSi\FixturesBundle\Form\NewsType;
12
use Symfony\Component\Form\FormFactoryInterface;
13
14
class News extends CRUDElement
15
{
16
    public function getId()
17
    {
18
        return 'news';
19
    }
20
21
    public function getClassName()
22
    {
23
        return 'FSi\FixturesBundle\Entity\News';
24
    }
25
26
    protected function initDataGrid(DataGridFactoryInterface $factory)
27
    {
28
        /* @var $datagrid \FSi\Component\DataGrid\DataGrid */
29
        $datagrid = $factory->createDataGrid('news');
30
31
        NewsDataGridBuilder::buildNewsDataGrid($datagrid);
32
33
        $datagrid->addColumn('actions', 'action', [
34
            'label' => 'admin.news.list.actions',
35
            'field_mapping' => ['id'],
36
            'actions' => [
37
                'edit' => [
38
                    'route_name' => "fsi_admin_crud_edit",
39
                    'additional_parameters' => ['element' => $datagrid->getName()],
40
                    'parameters_field_mapping' => ['id' => 'id']
41
                ],
42
                'display' => ['element' => DisplayNews::ID]
43
            ]
44
        ]);
45
46
        return $datagrid;
47
    }
48
49
    protected function initDataSource(DataSourceFactoryInterface $factory)
50
    {
51
        /* @var $datasource \FSi\Component\DataSource\DataSource */
52
        $datasource = $factory->createDataSource('doctrine', ['entity' => $this->getClassName()], 'news');
53
54
        NewsDataSourceBuilder::buildNewsDataSource($datasource);
55
56
        return $datasource;
57
    }
58
59
    protected function initForm(FormFactoryInterface $factory, $data = null)
60
    {
61
        return $factory->createNamed(
62
            'news',
63
            TypeSolver::getFormType('FSi\FixturesBundle\Form\NewsType', new NewsType()),
0 ignored issues
show
Bug introduced by
It seems like \FSi\Bundle\AdminBundle\...Bundle\Form\NewsType()) targeting FSi\Bundle\AdminBundle\F...peSolver::getFormType() can also be of type object<Symfony\Component\Form\FormTypeInterface>; however, Symfony\Component\Form\F...nterface::createNamed() 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...
64
            $data
65
        );
66
    }
67
}
68