Completed
Pull Request — master (#99)
by De Cramer
02:42
created

MapsWindowFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 86
Duplicated Lines 56.98 %

Coupling/Cohesion

Components 2
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 6
dl 49
loc 86
ccs 0
cts 58
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 17 17 1
B createGrid() 32 32 1
A setMaps() 0 16 2

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\Bundle\Maps\Plugins\Gui;
5
6
use eXpansion\Bundle\Acme\Plugins\Gui\WindowFactory;
7
use eXpansion\Bundle\LocalRecords\Entity\Record;
8
use eXpansion\Framework\Core\Helpers\Time;
9
use eXpansion\Framework\Core\Model\Gui\Grid\DataCollectionFactory;
10
use eXpansion\Framework\Core\Model\Gui\Grid\GridBuilder;
11
use eXpansion\Framework\Core\Model\Gui\Grid\GridBuilderFactory;
12
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface;
13
use eXpansion\Framework\Core\Model\Gui\WindowFactoryContext;
14
use eXpansion\Framework\Core\Plugins\Gui\GridWindowFactory;
15
use FML\Controls\Frame;
16
use Maniaplanet\DedicatedServer\Structures\Map;
17
18
19
/**
20
 * Class RecordsWindowFactory
21
 *
22
 * @package eXpansion\Bundle\LocalRecords\Plugins\Gui;
23
 * @author  reaby
24
 */
25
class MapsWindowFactory extends GridWindowFactory
26
{
27
    /** @var GridBuilderFactory */
28
    protected $gridBuilderFactory;
29
30
    /** @var DataCollectionFactory */
31
    protected $dataCollectionFactory;
32
33
    /** @var Time */
34
    protected $timeFormatter;
35
36 View Code Duplication
    public function __construct(
1 ignored issue
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...
37
        $name,
38
        $sizeX,
39
        $sizeY,
40
        $posX,
41
        $posY,
42
        WindowFactoryContext $context,
43
        GridBuilderFactory $gridBuilderFactory,
44
        DataCollectionFactory $dataCollectionFactory,
45
        Time $time
46
    ) {
47
        parent::__construct($name, $sizeX, $sizeY, $posX, $posY, $context);
48
49
        $this->gridBuilderFactory = $gridBuilderFactory;
50
        $this->dataCollectionFactory = $dataCollectionFactory;
51
        $this->timeFormatter = $time;
52
    }
53
54
55
    /**
56
     * @param ManialinkInterface $manialink
57
     * @return void
58
     */
59 View Code Duplication
    protected function createGrid(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...
60
    {
61
        $collection = $this->dataCollectionFactory->create($this->getData());
62
        $collection->setPageSize(20);
63
64
        $gridBuilder = $this->gridBuilderFactory->create();
65
        $gridBuilder->setManialink($manialink)
66
            ->setDataCollection($collection)
67
            ->setManialinkFactory($this)
68
            ->addTextColumn(
69
                'index',
70
                'expansion_maps.gui.window.column.index',
71
                '1',
72
                true
73
            )->addTextColumn(
74
                'name',
75
                'expansion_maps.gui.window.column.name',
76
                '3',
77
                true
78
            )->addTextColumn(
79
                'author',
80
                'expansion_maps.gui.window.column.author',
81
                '4'
82
            )->addTextColumn(
83
                'time',
84
                'expansion_maps.gui.window.column.goldtime',
85
                '3',
86
                true
87
            );
88
89
        $manialink->setData('grid', $gridBuilder);
90
    }
91
92
93
    public function setMaps($maps)
94
    {
95
        /**
96
         * @var string $i
97
         * @var Map $map
98
         */
99
        $i = 1;
100
        foreach ($maps as $uid => $map) {
101
            $this->genericData[] = [
102
                'index' => $i++,
103
                'name' => $map->name,
104
                'author' => $map->author,
105
                'time' => $this->timeFormatter->timeToText($map->goldTime, true),
106
            ];
107
        }
108
    }
109
110
}
111