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

WidgetCurrentMap::setStatus()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
ccs 0
cts 5
cp 0
cc 2
eloc 5
nc 2
nop 1
crap 6
1
<?php
2
3
namespace eXpansion\Bundle\WidgetCurrentMap\Plugins;
4
5
use eXpansion\Bundle\LocalMapRatings\DataProviders\Listener\ListenerInterfaceExpMapRatings;
6
use eXpansion\Bundle\LocalMapRatings\Model\Maprating;
7
use eXpansion\Bundle\WidgetCurrentMap\Plugins\Gui\CurrentMapWidgetFactory;
8
use eXpansion\Framework\Core\Model\UserGroups\Group;
9
use eXpansion\Framework\Core\Plugins\StatusAwarePluginInterface;
10
use eXpansion\Framework\Core\Storage\PlayerStorage;
11
use eXpansion\Framework\GameManiaplanet\DataProviders\Listener\ListenerInterfaceMpLegacyMap;
12
use Maniaplanet\DedicatedServer\Connection;
13
use Maniaplanet\DedicatedServer\Structures\Map;
14
15
16
class WidgetCurrentMap implements StatusAwarePluginInterface, ListenerInterfaceMpLegacyMap, ListenerInterfaceExpMapRatings
17
{
18
    /** @var Connection */
19
    protected $connection;
20
    /**
21
     * @var PlayerStorage
22
     */
23
    private $playerStorage;
24
    /**
25
     * @var CurrentMapWidgetFactory
26
     */
27
    private $widget;
28
    /**
29
     * @var Group
30
     */
31
    private $players;
32
33
    /**
34
     * Debug constructor.
35
     *
36
     * @param Connection              $connection
37
     * @param PlayerStorage           $playerStorage
38
     * @param CurrentMapWidgetFactory $widget
39
     * @param Group                   $players
40
     */
41 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
        Connection $connection,
43
        PlayerStorage $playerStorage,
44
        CurrentMapWidgetFactory $widget,
45
        Group $players
46
    ) {
47
        $this->connection = $connection;
48
        $this->playerStorage = $playerStorage;
49
        $this->widget = $widget;
50
        $this->players = $players;
51
    }
52
53
54
    public function setStatus($status)
55
    {
56
        if ($status) {
57
            $this->widget->create($this->players);
58
        } else {
59
            $this->widget->destroy($this->players);
60
        }
61
    }
62
63
    /**
64
     * @param Map $map
65
     *
66
     * @return void
67
     */
68
    public function onBeginMap(Map $map)
69
    {
70
        $this->widget->update($this->players);
71
    }
72
73
    /**
74
     * @param Map $map
75
     *
76
     * @return void
77
     */
78
    public function onEndMap(Map $map)
79
    {
80
81
    }
82
83
    /**
84
     * Called when map ratings are loaded.
85
     *
86
     * @param Maprating[] $ratings
87
     * @return void
88
     */
89
    public function onMapRatingsLoaded($ratings)
90
    {
91
        $this->widget->setMapRatings($ratings);
92
        $this->widget->update($this->players);
93
    }
94
95
    /**
96
     * Called when map ratings are changed.
97
     *
98
     * @param string      $login
99
     * @param int         $score
100
     * @param Maprating[] $ratings
101
     * @return void
102
     */
103
    public function onMapRatingsChanged($login, $score, $ratings)
104
    {
105
        $this->widget->setMapRatings($ratings);
106
        $this->widget->update($this->players);
107
    }
108
}
109