Completed
Push — master ( 3a8823...81c6e7 )
by Piotr
02:46
created

ListWorker::mount()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 5
nop 1
1
<?php
2
3
namespace FSi\Bundle\AdminBundle\Factory\Worker;
4
5
use FSi\Bundle\AdminBundle\Admin\CRUD\DataGridAwareInterface;
6
use FSi\Bundle\AdminBundle\Admin\CRUD\DataSourceAwareInterface;
7
use FSi\Bundle\AdminBundle\Admin\CRUD\ListElement;
8
use FSi\Bundle\AdminBundle\Admin\Element;
9
use FSi\Bundle\AdminBundle\Factory\Worker;
10
use FSi\Component\DataGrid\DataGridFactoryInterface;
11
use FSi\Component\DataSource\DataSourceFactoryInterface;
12
13
class ListWorker implements Worker
14
{
15
    /**
16
     * @var DataSourceFactoryInterface
17
     */
18
    private $dataSourceFactory;
19
20
    /**
21
     * @var \FSi\Component\DataGrid\DataGridFactoryInterface
22
     */
23
    private $dataGridFactory;
24
25
    /**
26
     * @param DataSourceFactoryInterface $dataSourceFactory
27
     */
28
    function __construct(
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
29
        DataSourceFactoryInterface $dataSourceFactory,
30
        DataGridFactoryInterface $dataGridFactory
31
    ) {
32
        $this->dataSourceFactory = $dataSourceFactory;
33
        $this->dataGridFactory = $dataGridFactory;
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    public function mount(Element $element)
40
    {
41
        if ($element instanceof ListElement) {
42
            $element->setDataSourceFactory($this->dataSourceFactory);
43
            $element->setDataGridFactory($this->dataGridFactory);
44
            return;
45
        }
46
        if ($element instanceof DataSourceAwareInterface) {
47
            $element->setDataSourceFactory($this->dataSourceFactory);
48
        }
49
        if ($element instanceof DataGridAwareInterface) {
50
            $element->setDataGridFactory($this->dataGridFactory);
51
        }
52
    }
53
}
54