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

WidgetCurrentMap   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 93
Duplicated Lines 11.83 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 11
loc 93
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 1
A setStatus() 0 8 2
A onBeginMap() 0 4 1
A onEndMap() 0 4 1
A onMapRatingsLoaded() 0 5 1
A onMapRatingsChanged() 0 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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