Completed
Pull Request — master (#75)
by
unknown
02:24
created

MapsWindowFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 68
Duplicated Lines 47.06 %

Coupling/Cohesion

Components 2
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 2
cbo 6
dl 32
loc 68
ccs 0
cts 42
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
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\Plugins\Gui\GridWindowFactory;
14
use FML\Controls\Frame;
15
use Maniaplanet\DedicatedServer\Structures\Map;
16
17
18
/**
19
 * Class RecordsWindowFactory
20
 *
21
 * @package eXpansion\Bundle\LocalRecords\Plugins\Gui;
22
 * @author  reaby
23
 */
24
class MapsWindowFactory extends GridWindowFactory
25
{
26
27
    /** @var GridBuilderFactory */
28
    protected $gridBuilderFactory;
29
30
    /** @var DataCollectionFactory */
31
    protected $dataCollectionFactory;
32
33
    /** @var Time */
34
    protected $timeFormatter;
35
36
    /**
37
     * @param ManialinkInterface $manialink
38
     * @return void
39
     */
40 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...
41
    {
42
        $collection = $this->dataCollectionFactory->create($this->getData());
43
        $collection->setPageSize(20);
44
45
        $gridBuilder = $this->gridBuilderFactory->create();
46
        $gridBuilder->setManialink($manialink)
47
            ->setDataCollection($collection)
48
            ->setManialinkFactory($this)
49
            ->addTextColumn(
50
                'index',
51
                'expansion_maps.gui.window.column.index',
52
                '1',
53
                true
54
            )->addTextColumn(
55
                'name',
56
                'expansion_maps.gui.window.column.name',
57
                '3',
58
                true
59
            )->addTextColumn(
60
                'author',
61
                'expansion_maps.gui.window.column.author',
62
                '4'
63
            )->addTextColumn(
64
                'time',
65
                'expansion_maps.gui.window.column.goldtime',
66
                '3',
67
                true
68
            );
69
70
        $manialink->setData('grid', $gridBuilder);
71
    }
72
73
74
    public function setMaps($maps)
75
    {
76
        /**
77
         * @var string $i
78
         * @var Map $map
79
         */
80
        $i = 1;
81
        foreach ($maps as $uid => $map) {
82
            $this->genericData[] = [
83
                'index' => $i++,
84
                'name' => $map->name,
85
                'author' => $map->author,
86
                'time' => $this->timeFormatter->timeToText($map->goldTime, true),
87
            ];
88
        }
89
    }
90
91
}
92