Completed
Pull Request — master (#154)
by De Cramer
02:58
created

MemoryWidgetFactory::createContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 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\Model\Gui\WidgetFactoryContext;
9
use eXpansion\Framework\Core\Plugins\Gui\WidgetFactory;
10
use eXpansion\Framework\Gui\Ui\Factory;
11
use FML\Controls\Label;
12
use FML\Script\Script;
13
use FML\Script\ScriptLabel;
14
15
class MemoryWidgetFactory extends WidgetFactory
16
{
17
    /** @var  Label */
18
    protected $memoryMessage;
19
20
    /** @var Factory */
21
    protected $uiFactory;
22
23
    public static $exp_hash;
24
25
    public function __construct(
26
        $name,
27
        $sizeX,
28
        $sizeY,
29
        $posX,
30
        $posY,
31
        WidgetFactoryContext $context,
32
        Factory $uiFactory
33
    ) {
34
        parent::__construct($name, $sizeX, $sizeY, $posX, $posY, $context);
35
        $this->uiFactory = $uiFactory;
36
    }
37
38
    /**
39
     * @param ManialinkInterface|Widget $manialink
40
     */
41
    protected function createContent(ManialinkInterface $manialink)
42
    {
43
44
        $this->memoryMessage = $this->uiFactory->createLabel("awaiting data...");
45
        $this->memoryMessage->setTextPrefix('$s')->setTextSize(3)->setSize(60, 5);
46
        $manialink->addChild($this->memoryMessage);
47
48
        self::$exp_hash = uniqid("exp");
49
    }
50
51
    protected function updateContent(ManialinkInterface $manialink)
52
    {
53
54
        $this->memoryMessage->setText(Test::$memoryMsg);
55
        $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...
56
57
        $message = "Time now:".date("h:i:s");
58
59
        $hash = self::$exp_hash;
60
61
        $script = new Script();
62
        $script->addCustomScriptLabel(ScriptLabel::OnInit,
63
            '
64
           declare Text '.$hash.' for LocalUser = Text;
65
           '.$hash.' = "'.$message.'";
66
           declare Text '.$hash.'_check for LocalUser = "";
67
           '.$hash.'_check = "$now";
68
           '
69
        );
70
        $manialink->getFmlManialink()->setScript($script);
71
    }
72
73
}
74