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

UpdateVoteWidgetFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 38
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A updateVote() 0 10 1
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
}