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

MapRatingsWidget::updateContent()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

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