Completed
Pull Request — master (#292)
by De Cramer
07:27 queued 01:23
created

UpdaterWidgetFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 5
crap 2
1
<?php
2
3
namespace eXpansion\Bundle\WidgetBestCheckpoints\Plugins\Gui;
4
5
use eXpansion\Framework\Core\Model\Gui\WidgetFactoryContext;
6
use eXpansion\Framework\Core\Model\UserGroups\Group;
7
use eXpansion\Framework\Core\Plugins\Gui\ScriptVariableUpdateFactory;
8
use FML\Script\Builder;
9
10
class UpdaterWidgetFactory extends ScriptVariableUpdateFactory
11
{
12
    protected $playerGroup;
13
14
    public function __construct(
15
        $name,
16
        array $variables,
17
        int $maxUpdateFrequency = 1,
18
        WidgetFactoryContext $context,
19
        Group $playerGroup
20
    ) {
21
        parent::__construct($name, $variables, $maxUpdateFrequency, $context);
22
        $this->playerGroup = $playerGroup;
23
    }
24
25
    /**
26
     * Update with new local record.
27
     *
28
     * @param array $checkpoints
29
     */
30
    public function setLocalRecord($checkpoints)
31
    {
32
        if (count($checkpoints) > 0) {
33
            $this->updateValue($this->playerGroup ,'LocalRecordCheckpoints', Builder::getArray($checkpoints, true));
34
        } else {
35
            $this->updateValue($this->playerGroup ,'LocalRecordCheckpoints', "Integer[Integer]");
36
        }
37
    }
38
}
39