Completed
Pull Request — master (#191)
by De Cramer
04:00
created

RaceDataProvider::isCompatible()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.2
c 0
b 0
f 0
ccs 0
cts 10
cp 0
cc 4
eloc 10
nc 5
nop 1
crap 20
1
<?php
2
3
namespace eXpansion\Framework\GameTrackmania\DataProviders\ScriptTimeAttack;
4
5
use eXpansion\Framework\Core\Storage\GameDataStorage;
6
use \eXpansion\Framework\GameTrackmania\DataProviders\ScriptBaseRounds\RaceDataProvider as RoundRaceDataProvider;
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 RoundRaceDataProvider
17
{
18
    /**
19
     * @var GameDataStorage
20
     */
21
    protected $gameDataStorage;
22
23
    /**
24
     * RaceDataProvider constructor.
25
     *
26
     * @param GameDataStorage $gameDataStorage
27
     */
28
    public function __construct(GameDataStorage $gameDataStorage)
29
    {
30
        $this->gameDataStorage = $gameDataStorage;
31
    }
32
33
34
    /**
35
     * Check if data provider is compatible with current situation.
36
     *
37
     * @return bool
38
     */
39
    public function isCompatible(Map $map): bool
40
    {
41
        if (!$map->lapRace) {
42
            return false;
43
        }
44
45
        $nbLaps = 1;
46
        if ($map->lapRace) {
47
            $nbLaps = $map->nbLaps;
48
        }
49
50
        $scriptSettings = $this->gameDataStorage->getScriptOptions();
51
        if ($scriptSettings['S_ForceLapsNb'] != -1) {
52
            $nbLaps = $scriptSettings['S_ForceLapsNb'];
53
        }
54
55
        // If rounds is configured to be single laps then no need for race data. lap is sufficient.
56
        return $nbLaps > 1;
57
    }
58
}
59