Completed
Pull Request — master (#311)
by De Cramer
06:47
created

WidgetFactory::updateOptions()   C

Complexity

Conditions 7
Paths 16

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 6.7272
c 0
b 0
f 0
ccs 0
cts 0
cp 0
cc 7
eloc 11
nc 16
nop 3
crap 56
1
<?php
2
3
namespace eXpansion\Framework\Core\Plugins\Gui;
4
use eXpansion\Framework\Core\DataProviders\Listener\ListenerExpWidgetPosition;
5
use eXpansion\Framework\Core\Model\Gui\Factory\WidgetFrameFactoryInterface;
6
use eXpansion\Framework\Core\Model\Gui\FmlManialink;
7
use eXpansion\Framework\Core\Model\Gui\WidgetFactoryContext;
8
use eXpansion\Framework\Core\Model\Gui\Window;
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 WidgetFactory extends FmlManialinkFactory implements ListenerExpWidgetPosition
18
{
19
    /** @var WidgetFrameFactoryInterface */
20
    protected $widgetFrameFactory;
21
22
    /** @var float */
23
    protected $defaultPositionX;
24
25
    /** @var float */
26
    protected $defaultPositionY;
27
28
    /**
29
     * WidgetFactory constructor.
30
     *
31
     * @param                      $name
32
     * @param                      $sizeX
33
     * @param                      $sizeY
34
     * @param null                 $posX
35
     * @param null                 $posY
36
     * @param WidgetFactoryContext $context
37
     */
38
    public function __construct(
39
        $name,
40
        $sizeX,
41
        $sizeY,
42
        $posX,
43
        $posY,
44
        WidgetFactoryContext $context
45
    ) {
46
        parent::__construct(
47
            $name,
48
            $sizeX,
49
            $sizeY,
50
            $posX,
51
            $posY,
52
            $context
53
        );
54
55
        $this->translationsHelper = $context->getTranslationsHelper();
56
        $this->uiFactory = $context->getUiFactory();
57
        $this->widgetFrameFactory = $context->getWidgetFrameFactory();
58
59
        $this->defaultPositionX = $posX;
60
        $this->defaultPositionY = $posY;
61
    }
62
63
    /**
64
     * @param Group $group
65
     *
66
     * @return Window
67
     */
68 View Code Duplication
    protected function createManialink(Group $group, $hideable = true)
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
71
        $className = $this->className;
72
        $manialink = new $className(
73
            $this,
74
            $group,
75
            $this->translationsHelper,
76
            $this->widgetFrameFactory,
77
            $this->name,
78
            $this->sizeX,
79
            $this->sizeY,
80
            $this->posX,
81
            $this->posY,
82
            $hideable
83
        );
84
85
        return $manialink;
86
    }
87
88
    /**
89
     * @inheritdoc
90
     */
91
    public function updateOptions($posX, $posY, $options)
92
    {
93
        $posX = !is_null($posX) ? $posX : $this->defaultPositionX;
94
        $posY = !is_null($posY) ? $posY : $this->defaultPositionY;
95
96
        // Check if changed.
97
        if ($this->posX == $posX && $this->posY == $posY) {
98
            return;
99
        }
100
101
        // Update position for future widgets.
102
        $this->posX = $posX;
103
        $this->posY = $posY;
104
105
        // Update current widgets.
106
       foreach ($this->guiHandler->getFactoryManialinks($this) as $manialink) {
107
           if ($manialink instanceof FmlManialink) {
0 ignored issues
show
Bug introduced by
The class eXpansion\Framework\Core\Model\Gui\FmlManialink does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
108
               $manialink->setPosition($this->posX, $this->posY);
109
           }
110
111
           $this->update($manialink->getUserGroup());
112
       }
113
    }
114
}
115