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

RaceDataProvider::onWayPoint()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 13

Duplication

Lines 19
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 19
loc 19
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 14
cp 0
cc 2
eloc 13
nc 2
nop 1
crap 6
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