MethodGetScoresDataProvider::registerPlugin()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace eXpansion\Framework\GameTrackmania\DataProviders;
4
5
use eXpansion\Framework\Core\DataProviders\AbstractDataProvider;
6
use eXpansion\Framework\Core\ScriptMethods\AbstractScriptMethod;
7
use eXpansion\Framework\Core\DataProviders\MethodScriptDataProviderInterface;
8
use eXpansion\Framework\Core\Services\DedicatedConnection\Factory;
9
use Maniaplanet\DedicatedServer\Connection;
10
11
12
/**
13
 * Class MethodGetStoresDataProvider
14
 *
15
 * @author    de Cramer Oliver<[email protected]>
16
 * @copyright 2017 eXpansion
17
 * @package eXpansion\Framework\GameManiaplanet\DataProviders
18
 */
19
class MethodGetScoresDataProvider extends AbstractDataProvider implements MethodScriptDataProviderInterface
20
{
21
    /** @var Factory */
22
    protected $factory;
23
24
    /**
25
     * MethodGetScoresDataProvider constructor.
26
     *
27
     * @param Factory $factory
28
     */
29
    public function __construct(Factory $factory)
30
    {
31
        $this->factory = $factory;
32
    }
33
34
    /**
35
     * @inheritdoc
36
     *
37
     * @param string $pluginId
38
     * @param AbstractScriptMethod $pluginService
39
     */
40
    public function registerPlugin($pluginId, $pluginService)
41
    {
42
        parent::registerPlugin($pluginId, $pluginService);
43
44
        $pluginService->setCurrentDataProvider($this);
45
    }
46
47
48
    /**
49
     * Request call to fetch scores.
50
     *
51
     * @return void
52
     * @throws
53
     */
54
    public function request()
55
    {
56
        $this->factory->getConnection()->triggerModeScriptEvent("Trackmania.GetScores", ["responseid" => (string) time()]);
57
    }
58
59
    /**
60
     * Set scores.
61
     *
62
     * @param array $params
63
     */
64
    public function setScores($params)
65
    {
66
        $this->dispatch('set', [$params]);
67
    }
68
}
69