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

RaceDataProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 43
rs 10
c 0
b 0
f 0
ccs 0
cts 13
cp 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isCompatible() 0 19 4
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