Completed
Pull Request — master (#309)
by De Cramer
14:06
created

UpdateVoteWidgetFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 6
dl 0
loc 11
ccs 0
cts 4
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace eXpansion\Bundle\VoteManager\Plugins\Gui\Widget;
4
5
use eXpansion\Bundle\VoteManager\Services\VoteService;
6
use eXpansion\Bundle\VoteManager\Structures\Vote;
7
use eXpansion\Framework\Core\Model\Gui\WidgetFactoryContext;
8
use eXpansion\Framework\Core\Model\UserGroups\Group;
9
use eXpansion\Framework\Core\Plugins\Gui\ScriptVariableUpdateFactory;
10
use FML\Script\Builder;
11
12
13
class UpdateVoteWidgetFactory extends ScriptVariableUpdateFactory
14
{
15
16
    /**
17
     * @var Group
18
     */
19
    private $allPlayers;
20
21
    public function __construct(
22
        $name,
23
        array $variables,
24
        float $maxUpdateFrequency = 0.25,
25
        WidgetFactoryContext $context,
26
        VoteService $voteService,
27
        Group $allPlayers
28
    ) {
29
        parent::__construct($name, $variables, $maxUpdateFrequency, $context);
30
        $this->allPlayers = $allPlayers;
31
    }
32
33
    /**
34
     * Update votes
35
     *
36
     * @param Vote $vote
37
     */
38
    public function updateVote($vote)
39
    {
40
41
        $out = [
42
            "yes" => $vote->getYes(),
43
            "no" => $vote->getNo(),
44
        ];
45
46
        $this->updateValue($this->allPlayers, "VoteUpdater", Builder::getArray($out, true));
47
    }
48
49
50
}