Completed
Pull Request — master (#304)
by
unknown
04:02
created

TotoWindowFactory_old   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 155
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 7
dl 0
loc 155
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 1
C updateContent() 0 77 7
A callbackOk() 0 19 2
1
<?php
2
3
namespace eXpansion\Bundle\Acme\Plugins\Gui;
4
5
use eXpansion\Bundle\Maps\Services\JukeboxService;
6
use eXpansion\Framework\Core\Helpers\Time;
7
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface;
8
use eXpansion\Framework\Core\Model\Gui\Widget;
9
use eXpansion\Framework\Core\Model\Gui\WindowFactoryContext;
10
use eXpansion\Framework\Core\Plugins\Gui\WindowFactory as BaseWindowFactory;
11
use eXpansion\Framework\Core\Storage\MapStorage;
12
use eXpansion\Framework\Gui\Builders\uiBuilder;
13
14
class TotoWindowFactory_old extends BaseWindowFactory
15
{
16
    /**
17
     * @var MapStorage
18
     */
19
    private $mapStorage;
20
    /**
21
     * @var Time
22
     */
23
    private $time;
24
    /**
25
     * @var JukeboxService
26
     */
27
    private $jukeboxService;
28
29
    /**
30
     * TotoWindowFactory constructor.
31
     * @param                      $name
32
     * @param                      $sizeX
33
     * @param                      $sizeY
34
     * @param null                 $posX
35
     * @param null                 $posY
36
     * @param WindowFactoryContext $context
37
     * @param MapStorage           $mapStorage
38
     * @param Time                 $time
39
     * @param JukeboxService       $jukeboxService
40
     */
41
    public function __construct(
42
        $name,
43
        $sizeX,
44
        $sizeY,
45
        $posX = null,
46
        $posY = null,
47
        WindowFactoryContext $context,
48
        MapStorage $mapStorage,
49
        Time $time,
50
        JukeboxService $jukeboxService
51
    ) {
52
        parent::__construct($name, $sizeX, $sizeY, $posX, $posY, $context);
53
        $this->mapStorage = $mapStorage;
54
        $this->time = $time;
55
        $this->jukeboxService = $jukeboxService;
56
    }
57
58
    /**
59
     * @param ManialinkInterface|Widget $manialink
60
     */
61
    protected function updateContent(ManialinkInterface $manialink)
62
    {
63
        parent::updateContent($manialink);
64
65
        $manialink->getContentFrame()->removeAllChildren();
66
67
        $builder = new uiBuilder($this->uiFactory, $this->actionFactory, $manialink, $this);
68
69
        $maps = $this->mapStorage->getMaps();
70
71
        $current = $this->mapStorage->getCurrentMap();
72
73
        $queue = $this->jukeboxService->getMapQueue();
74
75
76
        $x = 0;
77
78
        $inc = '<uiLayoutLine margin="1">';
79
        foreach ($maps as $map) {
80
            $juke = "";
81
82
            if ($x % 8 == 0) {
83
                if ($x != 0) {
84
                    $inc .= '</uiLayoutRow>';
85
                }
86
                $inc .= '<uiLayoutRow margin="1">';
87
            }
88
89
            if ($map->uId == $current->uId) {
90
                $color = "0f03";
91
                $juke = "<uiLabel pos='1 -7' width='30' textColor='fff' textSize='1'>Map Currently Playing</uiLabel>";
92
            } else {
93
                $color = "fff3";
94
            }
95
96
97
98
            $n = $x + 1;
0 ignored issues
show
Unused Code introduced by
$n is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
99
100
101
            $idx = 1;
102
            $sym = "";
103
            $gtime = "";
104
            foreach ($queue as $qmap) {
105
                if ($map->uId == $qmap->getMap()->uId) {
106
                    $nick = $qmap->getPlayer()->getNickName();
107
                    $color = "ff03";
108
                    $sym = "⏳".$idx;
109
                    $juke = "<uiLabel pos='1 -7' width='30' textColor='fff' textSize='1'>In Queue. Wished by $nick</uiLabel>";
110
                }
111
                $idx += 1;
112
            }
113
114
            $inc .= <<<EOL
115
                <frame size="40 10">              
116
                     <uiLabel actionCallback='callbackOk' actionParam='{$map->uId}' pos="32 -1" textColor="fff" textSize="4">$sym</uiLabel>                 
117
                     <uiLabel pos="1 -1" width="30" textColor="fff" textSize="1.5">{$map->name}</uiLabel>
118
                     <uiLabel pos="1 -4" width="30" textColor="fff" textSize="1">{$map->author} / {$gtime}</uiLabel> 
119
                     $juke
120
                     <quad backgroundColor="$color" size="40 10"/>         
121
                </frame>
122
EOL;
123
            $x++;
124
        }
125
126
        $inc .= '</uiLayoutRow>';
127
        $inc .= '</uiLayoutLine>';
128
129
        $manialink->getContentFrame()->addChild($builder->build(/** @lang text */
130
            <<<EOL
131
<window id="main">
132
           $inc
133
</window>
134
EOL
135
        ));
136
137
    }
138
139
    /*
140
     * <uiLayoutRow margin="2.">
141
            <uiLayoutLine margin="2">
142
                <uiButton actionCallback="callbackOk" type="decorated" >Ok</uiButton>
143
                <uiButton>Cancel</uiButton>
144
            </uiLayoutLine>
145
        </uiLayoutRow>
146
     */
147
148
    /** @var ManialinkInterface $manialink */
149
    public function callbackOk(
150
        $manialink,
151
        $login,
152
        $entries,
153
        $args
154
    ) {
155
156
        $map = $this->mapStorage->getMap($args['id']);
157
        if ($this->jukeboxService->checkMap($map)) {
158
            $this->jukeboxService->removeMap($map, $login, false);
159
160
        } else {
161
            $this->jukeboxService->addMapLast($map, $login, false);
162
163
        }
164
165
166
        $this->update($manialink->getUserGroup());
167
    }
168
}
169