Completed
Push — master ( f31586...66eb65 )
by De Cramer
04:28
created

RaceDataProvider::isCompatible()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 10
cp 0
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 5
nop 1
crap 20
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