Completed
Pull Request — master (#75)
by
unknown
07:18
created

GridWindowFactory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 93
Duplicated Lines 13.98 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 6
dl 13
loc 93
ccs 0
cts 33
cp 0
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A createContent() 0 5 1
createGrid() 0 1 ?
A updateContent() 13 13 1
A setData() 0 4 1
A getData() 0 3 1
A setGridBuilderFactory() 0 4 1
A setDataCollectionFactory() 0 4 1
A setTimerFormatter() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
4
namespace eXpansion\Framework\Core\Plugins\Gui;
5
6
use eXpansion\Framework\Core\Helpers\Time;
7
use eXpansion\Framework\Core\Model\Gui\Grid\DataCollectionFactory;
8
use eXpansion\Framework\Core\Model\Gui\Grid\GridBuilder;
9
use eXpansion\Framework\Core\Model\Gui\Grid\GridBuilderFactory;
10
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface;
11
use FML\Controls\Frame;
12
13
/**
14
 * Class RecordsWindowFactory
15
 *
16
 * @package eXpansion\Bundle\LocalRecords\Plugins\Gui;
17
 * @author  reaby
18
 */
19
abstract class GridWindowFactory extends WindowFactory
20
{
21
    /** @var array */
22
    protected $genericData = [];
23
24
    /** @var GridBuilderFactory */
25
    protected $gridBuilderFactory;
26
27
    /** @var DataCollectionFactory */
28
    protected $dataCollectionFactory;
29
30
    /** @var Time */
31
    protected $timeFormatter;
32
33
    /**
34
     * @var
35
     */
36
    protected $gridBuilder;
37
38
    /**
39
     * @inheritdoc
40
     */
41
    protected function createContent(ManialinkInterface $manialink)
42
    {
43
        parent::createContent($manialink);
44
        $this->createGrid($manialink);
45
    }
46
47
48
    /**
49
     * @param ManialinkInterface $manialink
50
     * @return mixed
51
     */
52
    abstract protected function createGrid(ManialinkInterface $manialink);
53
54
55
    /**
56
     * @inheritdoc
57
     */
58 View Code Duplication
    protected function updateContent(ManialinkInterface $manialink)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
    {
60
        /** @var Frame $contentFrame */
61
        $contentFrame = $manialink->getContentFrame();
62
        $contentFrame->removeAllChildren();
63
64
        $collection = $this->dataCollectionFactory->create($this->getData());
65
        $collection->setPageSize(20);
66
67
        /** @var GridBuilder $gridBuilder */
68
        $gridBuilder = $manialink->getData('grid');
69
        $contentFrame->addChild($gridBuilder->build($contentFrame->getWidth(), $contentFrame->getHeight()));
70
    }
71
72
    /**
73
     * @param array $data
74
     */
75
    public function setData($data)
76
    {
77
        $this->genericData = $data;
78
    }
79
80
    /**
81
     * @return array
82
     */
83
    public function getData() {
84
        return $this->genericData;
85
    }
86
    /**
87
     * @param GridBuilderFactory $gridBuilderFactory
88
     */
89
    public function setGridBuilderFactory($gridBuilderFactory)
90
    {
91
        $this->gridBuilderFactory = $gridBuilderFactory;
92
    }
93
94
    /**
95
     * @param DataCollectionFactory $dataCollectionFactory
96
     */
97
    public function setDataCollectionFactory($dataCollectionFactory)
98
    {
99
        $this->dataCollectionFactory = $dataCollectionFactory;
100
    }
101
102
    /**
103
     * @param Time $time
104
     */
105
    public function setTimerFormatter(Time $time)
106
    {
107
        $this->timeFormatter = $time;
108
    }
109
110
111
}
112