Completed
Push — master ( 947184...ad3618 )
by
unknown
9s
created

BestRecords::checkRecordPlugin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace eXpansion\Bundle\WidgetBestRecords\Plugins;
4
5
use eXpansion\Bundle\LocalRecords\DataProviders\Listener\RecordsDataListener;
6
use eXpansion\Bundle\LocalRecords\Model\Record;
7
use eXpansion\Bundle\LocalRecords\Plugins\BaseRecords;
8
use eXpansion\Bundle\WidgetBestRecords\Plugins\Gui\BestRecordsWidgetFactory;
9
use eXpansion\Framework\Core\Model\UserGroups\Group;
10
use eXpansion\Framework\Core\Plugins\StatusAwarePluginInterface;
11
use eXpansion\Framework\Core\Services\DedicatedConnection\Factory;
12
use eXpansion\Framework\Core\Storage\PlayerStorage;
13
use eXpansion\Framework\GameManiaplanet\DataProviders\Listener\ListenerInterfaceMpLegacyMap;
14
use Maniaplanet\DedicatedServer\Connection;
15
use Maniaplanet\DedicatedServer\Structures\Map;
16
17
18
class BestRecords implements StatusAwarePluginInterface, RecordsDataListener, ListenerInterfaceMpLegacyMap
19
{
20
    /** @var Factory */
21
    protected $factory;
22
    /**
23
     * @var PlayerStorage
24
     */
25
    private $playerStorage;
26
    /**
27
     * @var BestRecordsWidgetFactory
28
     */
29
    private $widget;
30
    /**
31
     * @var Group
32
     */
33
    private $players;
34
35
    /**
36
     * @var Group
37
     */
38
    private $allPlayers;
39
40
41
    /**
42
     * Debug constructor.
43
     *
44
     * @param Connection               $connection
0 ignored issues
show
Bug introduced by
There is no parameter named $connection. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
45
     * @param PlayerStorage            $playerStorage
46
     * @param BestRecordsWidgetFactory $widget
47
     * @param Group                    $players
48
     * @param Group                    $allPlayers
49
     */
50 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...
51
        Factory $factory,
52
        PlayerStorage $playerStorage,
53
        BestRecordsWidgetFactory $widget,
54
        Group $players,
55
        Group $allPlayers
56
    ) {
57
        $this->factory = $factory;
58
        $this->playerStorage = $playerStorage;
59
        $this->widget = $widget;
60
        $this->players = $players;
61
        $this->allPlayers = $allPlayers;
62
    }
63
64
    /**
65
     * Set the status of the plugin
66
     *
67
     * @param boolean $status
68
     *
69
     * @return void
70
     */
71
    public function setStatus($status)
72
    {
73
        if ($status) {
74
            $map = $this->factory->getConnection()->getCurrentMapInfo();
75
            $this->widget->setAuthorTime($map->author, $map->goldTime);
76
            $this->widget->create($this->allPlayers);
77
        } else {
78
            $this->widget->destroy($this->allPlayers);
79
        }
80
    }
81
82
    /**
83
     * @inheritdoc
84
     */
85
    public function onLocalRecordsLoaded($records, BaseRecords $baseRecords)
86
    {
87
        if (!$this->checkRecordPlugin($baseRecords)) {
88
            return;
89
        }
90
91
        if (count($records) > 0) {
92
            $this->widget->setLocalRecord($records[0]);
93
        } else {
94
            $this->widget->setLocalRecord(null);
95
        }
96
        $this->widget->update($this->allPlayers);
97
    }
98
99
    /**
100
     * @inheritdoc
101
     */
102 View Code Duplication
    public function onLocalRecordsFirstRecord(Record $record, $records, $position, BaseRecords $baseRecords)
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...
103
    {
104
        if (!$this->checkRecordPlugin($baseRecords)) {
105
            return;
106
        }
107
108
        $this->widget->setLocalRecord($record);
109
        $this->widget->update($this->allPlayers);
110
    }
111
112
    /**
113
     * @inheritdoc
114
     */
115
    public function onLocalRecordsSameScore(Record $record, Record $oldRecord, $records, BaseRecords $baseRecords)
116
    {
117
118
    }
119
120
    /**
121
     * @inheritdoc
122
     */
123 View Code Duplication
    public function onLocalRecordsBetterPosition(Record $record, Record $oldRecord, $records, $position, $oldPosition, BaseRecords $baseRecords)
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...
124
    {
125
        if (!$this->checkRecordPlugin($baseRecords)) {
126
            return;
127
        }
128
129
        if ($position == 1) {
130
            $this->widget->setLocalRecord($record);
131
            $this->widget->update($this->allPlayers);
132
        }
133
    }
134
135
    /**
136
     * @inheritdoc
137
     */
138 View Code Duplication
    public function onLocalRecordsSamePosition(Record $record, Record $oldRecord, $records, $position, BaseRecords $baseRecords)
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...
139
    {
140
        if (!$this->checkRecordPlugin($baseRecords)) {
141
            return;
142
        }
143
144
        if ($position == 1) {
145
            $this->widget->setLocalRecord($record);
146
            $this->widget->update($this->allPlayers);
147
        }
148
    }
149
150
151
    /**
152
     * @param Map $map
153
     *
154
     * @return void
155
     */
156
    public function onBeginMap(Map $map)
157
    {
158
        $this->widget->setAuthorTime($map->author, $map->authorTime);
159
    }
160
161
    /**
162
     * @param Map $map
163
     *
164
     * @return void
165
     */
166
    public function onEndMap(Map $map)
167
    {
168
169
    }
170
171
    /**
172
     * Check if we can use the data for this plugin.
173
     *
174
     * @param BaseRecords $baseRecords
175
     *
176
     * @return bool
177
     */
178
    protected function checkRecordPlugin(BaseRecords $baseRecords)
179
    {
180
        return $baseRecords->getRecordsHandler()->getCurrentNbLaps() == 1;
181
    }
182
}
183