Completed
Pull Request — master (#152)
by
unknown
02:44
created

MemoryWidgetFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 46
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createContent() 0 9 1
B updateContent() 0 24 1
1
<?php
2
3
namespace eXpansion\Bundle\Acme\Plugins\Gui;
4
5
use eXpansion\Bundle\Acme\Plugins\Test;
6
use eXpansion\Framework\Core\Model\Gui\ManialinkInterface;
7
use eXpansion\Framework\Core\Model\Gui\Widget;
8
use eXpansion\Framework\Core\Plugins\Gui\WidgetFactory;
9
10
use FML\Controls\Label;
11
use FML\Script\Script;
12
use FML\Script\ScriptLabel;
13
14
class MemoryWidgetFactory extends WidgetFactory
15
{
16
    /** @var  Label */
17
    protected $memoryMessage;
18
19
    public static $exp_hash;
20
21
    /**
22
     * @param ManialinkInterface|Widget $manialink
23
     */
24
    protected function createContent(ManialinkInterface $manialink)
25
    {
26
27
        $this->memoryMessage = new Label();
28
        $this->memoryMessage->setTextPrefix('$s')->setText("waiting data...");
29
        $manialink->addChild($this->memoryMessage);
30
31
        self::$exp_hash = uniqid("exp");
32
    }
33
34
    protected function updateContent(ManialinkInterface $manialink)
35
    {
36
37
        $this->memoryMessage->setText(Test::$memoryMsg);
38
        $now = uniqid("exp2");
0 ignored issues
show
Unused Code introduced by
$now 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...
39
40
        $message = "Time now:".date("h:i:s");
41
42
43
44
45
        $hash = self::$exp_hash;
46
47
        $script = new Script();
48
        $script->addCustomScriptLabel(ScriptLabel::OnInit,
49
            '
50
           declare Text '.$hash.' for LocalUser = Text;
51
           '.$hash.' = "'.$message.'";
52
           declare Text '.$hash.'_check for LocalUser = "";
53
           '.$hash.'_check = "$now";
54
           '
55
        );
56
        $manialink->getFmlManialink()->setScript($script);
57
    }
58
59
}
60