Completed
Push — dev ( 845ef5...8eacd8 )
by
unknown
02:50
created

WindowFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 88
Duplicated Lines 31.82 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 28
loc 88
ccs 0
cts 35
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 28 28 1
B createManialink() 0 24 1
A closeManialink() 0 6 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
namespace eXpansion\Framework\Core\Plugins\Gui;
4
use eXpansion\Framework\Core\Helpers\Translations;
5
use eXpansion\Framework\Core\Model\Gui\Manialink;
6
use eXpansion\Framework\Core\Model\Gui\ManiaScriptFactory;
7
use eXpansion\Framework\Core\Model\Gui\Window;
8
use eXpansion\Framework\Core\Model\UserGroups\Group;
9
use eXpansion\Framework\Core\Plugins\GuiHandler;
10
use eXpansion\Framework\Core\Plugins\UserGroups\Factory;
11
use FML\Controls\Control;
12
13
/**
14
 * Class ManialiveFactory allow the creation of manialinks.
15
 *
16
 * @package eXpansion\Framework\Core\Plugins\Gui
17
 * @author Oliver de Cramer
18
 */
19
class WindowFactory extends WidgetFactory {
20
21
    /** @var ManiaScriptFactory */
22
    protected $windowManiaScriptFactory;
23
24
    /**
25
     * WindowFactory constructor.
26
     *
27
     * @param                    $name
28
     * @param                    $sizeX
29
     * @param                    $sizeY
30
     * @param null               $posX
31
     * @param null               $posY
32
     * @param GuiHandler         $guiHandler
33
     * @param Factory            $groupFactory
34
     * @param ActionFactory      $actionFactory
35
     * @param ManiaScriptFactory $windowManiaScriptFactory
36
     * @param Translations       $translationsHelper
37
     * @param string             $className
38
     */
39 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...
40
        $name,
41
        $sizeX,
42
        $sizeY,
43
        $posX,
44
        $posY,
45
        GuiHandler $guiHandler,
46
        Factory $groupFactory,
47
        ActionFactory $actionFactory,
48
        ManiaScriptFactory $windowManiaScriptFactory,
49
        Translations $translationsHelper,
50
        $className = Window::class
51
    ) {
52
        parent::__construct(
53
            $name,
54
            $sizeX,
55
            $sizeY,
56
            $posX,
57
            $posY,
58
            $guiHandler,
59
            $groupFactory,
60
            $actionFactory,
61
            $translationsHelper,
62
            $className
63
        );
64
65
        $this->windowManiaScriptFactory = $windowManiaScriptFactory;
66
    }
67
68
69
70
    /**
71
     * @param Group $group
72
     *
73
     * @return Window
74
     */
75
    protected function createManialink(Group $group)
76
    {
77
        $className = $this->className;
78
        $manialink = new $className(
79
            $group,
80
            $this->windowManiaScriptFactory,
81
            $this->translationsHelper,
82
            $this->name,
83
            $this->sizeX,
84
            $this->sizeY,
85
            $this->posX,
86
            $this->posY
87
        );
88
89
        $actionId = $this->actionFactory->createManialinkAction(
90
            $manialink,
91
            [$this, 'closeManialink'],
92
            ['manialink' => $manialink]
93
        );
94
95
        $manialink->setCloseAction($actionId);
96
97
        return $manialink;
98
    }
99
100
    public function closeManialink($login, $answerValues, $arguments)
101
    {
102
        /** @var Manialink $manialink */
103
        $manialink = $arguments['manialink'];
104
        $this->destroy($manialink->getUserGroup());
105
    }
106
}
107