WindowFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 88
Duplicated Lines 23.86 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 21
loc 88
ccs 0
cts 52
cp 0
rs 10
c 0
b 0
f 0

4 Methods

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