Completed
Push — master ( b2309d...0cebbd )
by De Cramer
15s
created

BestCheckpoints::onEndMatchEnd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 2
cp 0
cc 1
eloc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace eXpansion\Bundle\WidgetBestCheckpoints\Plugins;
4
5
use eXpansion\Bundle\LocalRecords\DataProviders\Listener\RecordsDataListener;
6
use eXpansion\Bundle\LocalRecords\Model\Record;
7
use eXpansion\Bundle\WidgetBestCheckpoints\Plugins\Gui\BestCheckpointsWidgetFactory;
8
use eXpansion\Bundle\WidgetBestCheckpoints\Plugins\Gui\UpdaterWidgetFactory;
9
use eXpansion\Framework\Core\DataProviders\Listener\ListenerInterfaceExpApplication;
10
use eXpansion\Framework\Core\Model\UserGroups\Group;
11
use eXpansion\Framework\Core\Storage\PlayerStorage;
12
use eXpansion\Framework\GameManiaplanet\DataProviders\Listener\ListenerInterfaceMpScriptMatch;
13
use Maniaplanet\DedicatedServer\Connection;
14
15
16
class BestCheckpoints implements ListenerInterfaceExpApplication, RecordsDataListener, ListenerInterfaceMpScriptMatch
17
{
18
    /** @var Connection */
19
    protected $connection;
20
    /**
21
     * @var PlayerStorage
22
     */
23
    private $playerStorage;
24
    /**
25
     * @var BestCheckpointsWidgetFactory
26
     */
27
    private $widget;
28
    /**
29
     * @var Group
30
     */
31
    private $players;
32
    /**
33
     * @var UpdaterWidgetFactory
34
     */
35
    private $updater;
36
    /**
37
     * @var Group
38
     */
39
    private $allPlayers;
40
41
    private $justStarted = true;
0 ignored issues
show
Unused Code introduced by
The property $justStarted is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
42
43
    /**
44
     * Debug constructor.
45
     *
46
     * @param Connection                   $connection
47
     * @param PlayerStorage                $playerStorage
48
     * @param BestCheckPointsWidgetFactory $widget
49
     * @param UpdaterWidgetFactory         $updater
50
     * @param Group                        $players
51
     * @param Group                        $allPlayers
52
     */
53
    public function __construct(
54
        Connection $connection,
55
        PlayerStorage $playerStorage,
56
        BestCheckPointsWidgetFactory $widget,
57
        UpdaterWidgetFactory $updater,
58
        Group $players,
59
        Group $allPlayers
60
    ) {
61
        $this->connection = $connection;
62
        $this->playerStorage = $playerStorage;
63
        $this->widget = $widget;
64
        $this->players = $players;
65
        $this->updater = $updater;
66
        $this->allPlayers = $allPlayers;
67
    }
68
69
    /**
70
     * Set the status of the plugin
71
     *
72
     * @param boolean $status
73
     *
74
     * @return null
75
     */
76
    public function setStatus($status)
0 ignored issues
show
Unused Code introduced by
The parameter $status is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
77
    {
78
79
    }
80
81
    /**
82
     * called at eXpansion init
83
     *
84
     * @return void
85
     */
86
    public function onApplicationInit()
87
    {
88
89
90
    }
91
92
    /**
93
     * called when init is done and callbacks are enabled
94
     *
95
     * @return void
96
     */
97
    public function onApplicationReady()
98
    {
99
        $this->widget->create($this->players);
100
        $this->updater->create($this->allPlayers);
101
    }
102
103
    /**
104
     * called when requesting application stop
105
     *
106
     * @return void
107
     */
108
    public function onApplicationStop()
109
    {
110
111
    }
112
113
    /**
114
     * Called when local records are loaded.
115
     *
116
     * @param Record[] $records
117
     */
118
    public function onLocalRecordsLoaded($records)
119
    {
120
        if (count($records) > 0) {
121
            $this->updater->setLocalRecord($records[0]->getCheckpoints());
122
        } else {
123
            $this->updater->setLocalRecord([]);
124
        }
125
        $this->updater->update($this->allPlayers);
126
    }
127
128
    /**
129
     * Called when a player finishes map for the very first time (basically first record).
130
     *
131
     * @param Record   $record
132
     * @param Record[] $records
133
     * @param          $position
134
     */
135
    public function onLocalRecordsFirstRecord(Record $record, $records, $position)
136
    {
137
        $rec = $record->getCheckpoints();
138
        $this->updater->setLocalRecord($rec);
139
        $this->updater->update($this->allPlayers);
140
    }
141
142
    /**
143
     * Called when a player finishes map and does same time as before.
144
     *
145
     * @param Record   $record
146
     * @param Record   $oldRecord
147
     * @param Record[] $records
148
     */
149
    public function onLocalRecordsSameScore(Record $record, Record $oldRecord, $records)
150
    {
151
152
    }
153
154
    /**
155
     * Called when a player finishes map with better time and has better position.
156
     *
157
     * @param Record   $record
158
     * @param Record   $oldRecord
159
     * @param Record[] $records
160
     * @param int      $position
161
     * @param int      $oldPosition
162
     */
163 View Code Duplication
    public function onLocalRecordsBetterPosition(Record $record, Record $oldRecord, $records, $position, $oldPosition)
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...
164
    {
165
        if ($position == 1) {
166
            $this->updater->setLocalRecord($record->getCheckpoints());
167
            $this->updater->update($this->allPlayers);
168
        }
169
    }
170
171
    /**
172
     * Called when a player finishes map with better time but keeps same position.
173
     *
174
     * @param Record   $record
175
     * @param Record   $oldRecord
176
     * @param Record[] $records
177
     * @param          $position
178
     */
179 View Code Duplication
    public function onLocalRecordsSamePosition(Record $record, Record $oldRecord, $records, $position)
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...
180
    {
181
        if ($position == 1) {
182
            $this->updater->setLocalRecord($record->getCheckpoints());
183
            $this->updater->update($this->allPlayers);
184
        }
185
    }
186
187
    /**
188
     * Callback sent when the "StartMatch" section start.
189
     *
190
     * @param int $count Each time this section is played, this number is incremented by one
191
     * @param int $time  Server time when the callback was sent
192
     *
193
     * @return void
194
     */
195
    public function onStartMatchStart($count, $time)
196
    {
197
198
    }
199
200
    /**
201
     * Callback sent when the "StartMatch" section end.
202
     *
203
     * @param int $count Each time this section is played, this number is incremented by one
204
     * @param int $time  Server time when the callback was sent
205
     *
206
     * @return void
207
     */
208
    public function onStartMatchEnd($count, $time)
209
    {
210
     //  $this->updater->update($this->allPlayers);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
211
    }
212
213
    /**
214
     * Callback sent when the "EndMatch" section start.
215
     *
216
     * @param int $count Each time this section is played, this number is incremented by one
217
     * @param int $time  Server time when the callback was sent
218
     *
219
     * @return void
220
     */
221
    public function onEndMatchStart($count, $time)
222
    {
223
224
    }
225
226
    /**
227
     * Callback sent when the "EndMatch" section end.
228
     *
229
     * @param int $count Each time this section is played, this number is incremented by one
230
     * @param int $time  Server time when the callback was sent
231
     *
232
     * @return void
233
     */
234
    public function onEndMatchEnd($count, $time)
235
    {
236
237
    }
238
239
    /**
240
     * Callback sent when the "StartTurn" section start.
241
     *
242
     * @param int $count Each time this section is played, this number is incremented by one
243
     * @param int $time  Server time when the callback was sent
244
     *
245
     * @return void
246
     */
247
    public function onStartTurnStart($count, $time)
248
    {
249
250
    }
251
252
    /**
253
     * Callback sent when the "StartTurn" section end.
254
     *
255
     * @param int $count Each time this section is played, this number is incremented by one
256
     * @param int $time  Server time when the callback was sent
257
     *
258
     * @return void
259
     */
260
    public function onStartTurnEnd($count, $time)
261
    {
262
263
    }
264
265
    /**
266
     * Callback sent when the "EndMatch" section start.
267
     *
268
     * @param int $count Each time this section is played, this number is incremented by one
269
     * @param int $time  Server time when the callback was sent
270
     *
271
     * @return void
272
     */
273
    public function onEndTurnStart($count, $time)
274
    {
275
276
    }
277
278
    /**
279
     * Callback sent when the "EndMatch" section end.
280
     *
281
     * @param int $count Each time this section is played, this number is incremented by one
282
     * @param int $time  Server time when the callback was sent
283
     *
284
     * @return void
285
     */
286
    public function onEndTurnEnd($count, $time)
287
    {
288
289
    }
290
291
    /**
292
     * Callback sent when the "StartRound" section start.
293
     *
294
     * @param int $count Each time this section is played, this number is incremented by one
295
     * @param int $time  Server time when the callback was sent
296
     *
297
     * @return void
298
     */
299
    public function onStartRoundStart($count, $time)
300
    {
301
302
    }
303
304
    /**
305
     * Callback sent when the "StartRound" section end.
306
     *
307
     * @param int $count Each time this section is played, this number is incremented by one
308
     * @param int $time  Server time when the callback was sent
309
     *
310
     * @return void
311
     */
312
    public function onStartRoundEnd($count, $time)
313
    {
314
315
    }
316
317
    /**
318
     * Callback sent when the "EndMatch" section start.
319
     *
320
     * @param int $count Each time this section is played, this number is incremented by one
321
     * @param int $time  Server time when the callback was sent
322
     *
323
     * @return void
324
     */
325
    public function onEndRoundStart($count, $time)
326
    {
327
328
    }
329
330
    /**
331
     * Callback sent when the "EndMatch" section end.
332
     *
333
     * @param int $count Each time this section is played, this number is incremented by one
334
     * @param int $time  Server time when the callback was sent
335
     *
336
     * @return void
337
     */
338
    public function onEndRoundEnd($count, $time)
339
    {
340
341
    }
342
}
343