Completed
Pull Request — master (#168)
by De Cramer
08:32
created

MethodGetNumberLapsDataProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 55
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A registerPlugin() 0 6 1
A request() 0 16 3
1
<?php
2
3
namespace eXpansion\Framework\GameTrackmania\DataProviders\ScriptBaseRounds;
4
5
use eXpansion\Framework\Core\DataProviders\AbstractDataProvider;
6
use eXpansion\Framework\Core\DataProviders\MethodScriptDataProviderInterface;
7
use eXpansion\Framework\Core\Storage\MapStorage;
8
use Maniaplanet\DedicatedServer\Connection;
9
10
/**
11
 * Class MethodGetNumberLapsDataProvider
12
 *
13
 * @author    de Cramer Oliver<[email protected]>
14
 * @copyright 2017 eXpansion
15
 * @package eXpansion\Framework\GameTrackmania\DataProviders
16
 */
17
class MethodGetNumberLapsDataProvider extends AbstractDataProvider implements MethodScriptDataProviderInterface
18
{
19
    /** @var Connection */
20
    protected $connection;
21
22
    /** @var MapStorage */
23
    protected $mapStorage;
24
25
    /**
26
     * MethodGetNumberLapsDataProvider constructor.
27
     *
28
     * @param Connection $connection
29
     * @param MapStorage $mapStorage
30
     */
31
    public function __construct(Connection $connection, MapStorage $mapStorage)
32
    {
33
        $this->connection = $connection;
34
        $this->mapStorage = $mapStorage;
35
    }
36
37
    /**
38
     * @inheritdoc
39
     *
40
     * @param string $pluginId
41
     * @param mixed $pluginService
42
     */
43
    public function registerPlugin($pluginId, $pluginService)
44
    {
45
        parent::registerPlugin($pluginId, $pluginService);
46
47
        $pluginService->setCurrentDataProvider($this);
48
    }
49
50
    /**
51
     * Request call to fetch something..
52
     *
53
     * @return void
54
     */
55
    public function request()
56
    {
57
        $scriptSettings = $this->connection->getModeScriptSettings();
58
        $currentMap = $this->mapStorage->getCurrentMap();
59
60
        $nbLaps = 1;
61
        if ($currentMap->lapRace) {
62
            $nbLaps = $currentMap->nbLaps;
63
        }
64
65
        if ($scriptSettings['S_ForceLapsNb'] != -1) {
66
            $nbLaps = $scriptSettings['S_ForceLapsNb'];
67
        }
68
69
        $this->dispatch('set', [$nbLaps]);
70
    }
71
}
72