Completed
Pull Request — master (#180)
by De Cramer
03:01
created

RaceRecords   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 81
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 81
loc 81
ccs 14
cts 18
cp 0.7778
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A startMap() 10 10 3
A onPlayerEndRace() 21 21 3
A onPlayerEndLap() 14 14 1
A onPlayerWayPoint() 17 17 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\LocalRecords\Plugins;
4
5
use eXpansion\Framework\GameTrackmania\DataProviders\Listener\RaceDataListenerInterface as TmRaceDataListenerInterface;
6
7
/**
8
 * Class RaceRecords
9
 *
10
 * @package eXpansion\Bundle\LocalRecords\Plugins;
11
 * @author  oliver de Cramer <[email protected]>
12
 */
13 View Code Duplication
class RaceRecords extends BaseRecords implements TmRaceDataListenerInterface
0 ignored issues
show
Duplication introduced by
This class 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...
14
{
15
    /**
16
     * @inheritdoc
17
     */
18 2
    public function startMap($map, $nbLaps)
19
    {
20 2
        if ($nbLaps == 1 && $map->lapRace) {
21
            $this->logger->info("Disabling race records.", ['nbLaps' => $nbLaps, 'map' => $map->lapRace]);
22
            $this->status = false;
23
            return;
24
        }
25
26 2
        parent::startMap($map, $nbLaps);
27 2
    }
28
29
30
    /**
31
     * @inheritdoc
32
     */
33 2
    public function onPlayerEndRace(
34
        $login,
35
        $time,
36
        $raceTime,
37
        $stuntsScore,
38
        $cpInRace,
39
        $curCps,
40
        $blockId,
41
        $speed,
42
        $distance
43
    )
44
    {
45 2
        if (!$this->status) {
46
            return;
47
        }
48
49 2
        $eventData = $this->recordsHandler->addRecord($login, $raceTime, $curCps);
50 2
        if ($eventData) {
51 1
            $this->dispatchEvent($eventData);
52
        }
53 2
    }
54
55
    /*
56
     * @inheritdoc
57
     */
58 1
    public function onPlayerEndLap(
59
        $login,
60
        $time,
61
        $lapTime,
62
        $stuntsScore,
63
        $cpInLap,
64
        $curLapCps,
65
        $blockId,
66
        $speed,
67
        $distance
68
    )
69
    {
70
        // Nothing to do.
71 1
    }
72
73
    /*
74
     * @inheritdoc
75
     */
76 1
    public function onPlayerWayPoint(
77
        $login,
78
        $time,
79
        $raceTime,
80
        $lapTime,
81
        $stuntsScore,
82
        $cpInRace,
83
        $cpInLap,
84
        $curCps,
85
        $curLapCps,
86
        $blockId,
87
        $speed,
88
        $distance
89
    )
90
    {
91
        // Nothing to do.
92 1
    }
93
}
94