Completed
Pull Request — master (#167)
by
unknown
03:24
created

MapRatingsWidget::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
c 0
b 0
f 0
ccs 0
cts 4
cp 0
rs 9.4285
cc 1
eloc 10
nc 1
nop 7
crap 2
1
<?php
2
3
namespace eXpansion\Bundle\LocalMapRatings\Plugin\Gui;
4
5
use eXpansion\Bundle\LocalMapRatings\Services\MapRatingsService;
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\Components\uiLabel;
11
12
class MapRatingsWidget extends WidgetFactory
13
{
14
15
    /** @var uiLabel */
16
    private $lblRatings;
17
    /**
18
     * @var MapRatingsService
19
     */
20
    private $mapRatingsService;
21
22
    public function __construct(
23
        $name,
24
        $sizeX,
25
        $sizeY,
26
        $posX,
27
        $posY,
28
        WidgetFactoryContext $context,
29
        MapRatingsService $mapRatingsService
30
    ) {
31
        parent::__construct($name, $sizeX, $sizeY, $posX, $posY, $context);
32
33
        $this->mapRatingsService = $mapRatingsService;
34
    }
35
36
    protected function createContent(ManialinkInterface $manialink)
37
    {
38
        parent::createContent($manialink);
39
40
        $this->lblRatings = $this->uiFactory->createLabel("", uiLabel::TYPE_NORMAL);
41
        $this->lblRatings->setPosition(0, 0)->setSize(40, 6)
42
            ->setTextSize(2)->setAlign("right", "top");
43
        $manialink->addChild($this->lblRatings);
44
45
    }
46
47
48
    protected function updateContent(ManialinkInterface $manialink)
49
    {
50
        $ratings = $this->mapRatingsService->getRatingsPerPlayer();
51
        $total = count($ratings);
0 ignored issues
show
Unused Code introduced by
$total 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...
52
        $yes = 0;
53
        $no = 0;
54
        foreach ($ratings as $login => $rating) {
55
            $score = $rating->getScore();
56
57
            if ($score === 1) {
58
                $yes++;
59
            }
60
            if ($score === -1) {
61
                $no++;
62
            }
63
        }
64
65
        $this->lblRatings->setText('$0d0 $fff'.$yes.'   $d00 $fff'.$no); // for total add ."   👥 ".$total
66
    }
67
68
    /**
69
     * @param ManialinkInterface|Widget $manialink
70
     * @param string                    $login
71
     * @param array                     $entries
72
     * @param array                     $args
73
     */
74
    public function callbackVoteYes(ManialinkInterface $manialink, $login, $entries, $args)
75
    {
76
        $this->mapRatingsService->changeRating($login, 1);
77
        $this->update($manialink->getUserGroup());
78
    }
79
80
    /**
81
     * @param ManialinkInterface|Widget $manialink
82
     * @param string                    $login
83
     * @param array                     $entries
84
     * @param array                     $args
85
     */
86
    public function callbackVoteNo(ManialinkInterface $manialink, $login, $entries, $args)
87
    {
88
        $this->mapRatingsService->changeRating($login, -1);
89
        $this->update($manialink->getUserGroup());
90
    }
91
92
}
93