Completed
Pull Request — master (#191)
by De Cramer
38:49 queued 31:55
created

RaceDataProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 40.43 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 19
loc 47
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isCompatible() 0 18 4
A onWayPoint() 19 19 2

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\Framework\GameTrackmania\DataProviders\ScriptBaseRounds;
4
5
use eXpansion\Framework\Core\DataProviders\AbstractDataProvider;
6
use eXpansion\Framework\Core\Model\CompatibilityCheckDataProviderInterface;
7
use Maniaplanet\DedicatedServer\Structures\Map;
8
9
/**
10
 * Class RaceDataProvider
11
 *
12
 * @author    de Cramer Oliver<[email protected]>
13
 * @copyright 2017 Smile
14
 * @package eXpansion\Framework\GameTrackmania\DataProviders\ScriptBaseRounds
15
 */
16
class RaceDataProvider extends AbstractDataProvider implements CompatibilityCheckDataProviderInterface
17
{
18
    /**
19
     * Check if data provider is compatible with current situation.
20
     *
21
     * @return bool
22
     */
23
    public function isCompatible(Map $map): bool
24
    {
25
        if (!$map->lapRace) {
26
            return false;
27
        }
28
29
        $nbLaps = 1;
30
        if ($map->lapRace) {
31
            $nbLaps = $map->nbLaps;
32
        }
33
34
        $scriptSettings = $this->gameDataStorage->getScriptOptions();
35
        if ($scriptSettings['S_ForceLapsNb'] != -1) {
36
            $nbLaps = $scriptSettings['S_ForceLapsNb'];
37
        }
38
39
        // If rounds is configured to be single laps then no need for race data. lap is sufficient.
40
        return $nbLaps > 1;    }
41
42
43 View Code Duplication
    public function onWayPoint($params)
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...
44
    {
45
        if ($params['isendrace']) {
46
            $this->dispatch(
47
                'onPlayerEndRace',
48
                [
49
                    $params['login'],
50
                    $params['time'],
51
                    $params['racetime'],
52
                    $params['stuntsscore'],
53
                    $params['checkpointinrace'],
54
                    $params['curracecheckpoints'],
55
                    $params['blockid'],
56
                    $params['speed'],
57
                    $params['distance'],
58
                ]
59
            );
60
        }
61
    }
62
}
63