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

ListWorker   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A mount() 0 14 4
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