Completed
Pull Request — master (#329)
by De Cramer
03:46
created

DedirecsWindow::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 14

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 14
nc 1
nop 9
dl 17
loc 17
rs 9.4285
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
4
namespace eXpansionExperimantal\Bundle\Dedimania\Plugins\Gui;
5
6
7
use eXpansionExperimantal\Bundle\Dedimania\Structures\DedimaniaRecord;
8
use eXpansion\Framework\Core\Helpers\Time;
9
use eXpansion\Framework\Core\Helpers\TMString;
10
use eXpansion\Framework\Core\Model\Gui\Grid\DataCollectionFactory;
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
16
17
/**
18
 * Class RecordsWindowFactory
19
 *
20
 * @package eXpansion\Bundle\LocalRecords\Plugins\Gui;
21
 * @author  reaby
22
 */
23
class DedirecsWindow extends GridWindowFactory
24
{
25
    /** @var GridBuilderFactory */
26
    protected $gridBuilderFactory;
27
28
    /** @var DataCollectionFactory */
29
    protected $dataCollectionFactory;
30
31
    /** @var Time */
32
    protected $timeFormatter;
33
34
35
    /**
36
     * MapsWindowFactory constructor.
37
     * @param                       $name
38
     * @param                       $sizeX
39
     * @param                       $sizeY
40
     * @param null                  $posX
41
     * @param null                  $posY
42
     * @param WindowFactoryContext  $context
43
     * @param GridBuilderFactory    $gridBuilderFactory
44
     * @param DataCollectionFactory $dataCollectionFactory
45
     * @param Time                  $time
46
     */
47 View Code Duplication
    public function __construct(
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...
48
        $name,
49
        $sizeX,
50
        $sizeY,
51
        $posX,
52
        $posY,
53
        WindowFactoryContext $context,
54
        GridBuilderFactory $gridBuilderFactory,
55
        DataCollectionFactory $dataCollectionFactory,
56
        Time $time
57
    ) {
58
        parent::__construct($name, $sizeX, $sizeY, $posX, $posY, $context);
59
60
        $this->gridBuilderFactory = $gridBuilderFactory;
61
        $this->dataCollectionFactory = $dataCollectionFactory;
62
        $this->timeFormatter = $time;
63
    }
64
65
    /**
66
     * @param DedimaniaRecord[] $records
67
     */
68 View Code Duplication
    public function setRecords($records)
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...
69
    {
70
        $this->genericData = [];
71
72
        /**
73
         * @var string          $i
74
         * @var DedimaniaRecord $record
75
         */
76
        $i = 1;
77
        foreach ($records as $uid => $record) {
78
            $this->genericData[] = [
79
                'index' => $i++,
80
                'time' => $this->timeFormatter->timeToText($record->best, true),
81
                'name' => TMString::trimControls($record->nickName),
82
                'login' => $record->login,
83
            ];
84
        }
85
86
    }
87
88
    /**
89
     * @param ManialinkInterface $manialink
90
     * @return void
91
     */
92
    protected function createGrid(ManialinkInterface $manialink)
93
    {
94
        $this->setData($manialink, $this->genericData);
95
96
        $tooltip = $this->uiFactory->createTooltip();
97
        $manialink->addChild($tooltip);
98
99
        $gridBuilder = $this->gridBuilderFactory->create();
100
        $gridBuilder->setManialink($manialink)
101
            ->setDataCollection($manialink->getData('dataCollection'))
102
            ->setManialinkFactory($this)
103
            ->addTextColumn(
104
                'index',
105
                'expansion_dedimania.gui.window.column.index',
106
                1,
107
                true,
108
                false
109
            )->addTextColumn(
110
                'time',
111
                'expansion_dedimania.gui.window.column.time',
112
                2,
113
                true,
114
                false
115
116
            )->addTextColumn(
117
                'name',
118
                'expansion_dedimania.gui.window.column.name',
119
                5,
120
                true,
121
                false
122
            )->addTextColumn(
123
                'login',
124
                'expansion_dedimania.gui.window.column.login',
125
                3,
126
                false
127
            );
128
129
        $manialink->setData('grid', $gridBuilder);
130
131
    }
132
133
}
134