Completed
Push — dev ( 8eacd8...04be10 )
by De Cramer
02:44
created

BaseDataProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 99
rs 10
c 0
b 0
f 0
ccs 0
cts 41
cp 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A onStartMatchStart() 0 4 1
A onStartMatchEnd() 0 4 1
A onStartMapStart() 0 4 1
A onStartMapEnd() 0 4 1
A onEndMapStart() 0 4 1
A onEndMapEnd() 0 4 1
A dispatchMapEvent() 0 14 1
1
<?php
2
3
namespace eXpansion\Framework\GameManiaplanet\DataProviders;
4
5
use eXpansion\Framework\Core\DataProviders\AbstractDataProvider;
6
use eXpansion\Framework\Core\Storage\MapStorage;
7
8
9
/**
10
 * Class BaseDataProvider
11
 *
12
 * @package eXpansion\Framework\GameManiaplanet\DataProviders;
13
 * @author  oliver de Cramer <[email protected]>
14
 */
15
class BaseDataProvider extends AbstractDataProvider
16
{
17
    /** @var  MapStorage */
18
    protected $mapStorage;
19
20
    /**
21
     * BaseDataProvider constructor.
22
     *
23
     * @param MapStorage $mapStorage
24
     */
25
    public function __construct(MapStorage $mapStorage)
26
    {
27
        $this->mapStorage = $mapStorage;
28
    }
29
30
31
    /**
32
     * Callback sent when the "StartMatch" section start.
33
     *
34
     * @param array $params
35
     */
36
    public function onStartMatchStart($params)
37
    {
38
        $this->dispatch('onStartMatchStart', [$params['count'], $params['time']]);
39
    }
40
41
    /**
42
     * Callback sent when the "StartMatch" section end.
43
     *
44
     * @param array $params
45
     */
46
    public function onStartMatchEnd($params)
47
    {
48
        $this->dispatch('onStartMatchEnd', [$params['count'], $params['time']]);
49
    }
50
51
    /**
52
     * Callback sent when the "StartMap" section start.
53
     *
54
     * @param array $params
55
     */
56
    public function onStartMapStart($params)
57
    {
58
        $this->dispatchMapEvent('onStartMapStart', $params);
59
    }
60
61
    /**
62
     * Callback sent when the "StartMatch" section start.
63
     *
64
     * @param array $params
65
     */
66
    public function onStartMapEnd($params)
67
    {
68
        $this->dispatchMapEvent('onStartMapEnd', $params);
69
    }
70
71
72
    /**
73
     * Callback sent when the "EndMap" section start.
74
     *
75
     * @param array $params
76
     */
77
    public function onEndMapStart($params)
78
    {
79
        $this->dispatchMapEvent('onEndMapStart', $params);
80
    }
81
82
    /**
83
     * Callback sent when the "EndMap" section ends.
84
     *
85
     * @param array $params
86
     */
87
    public function onEndMapEnd($params)
88
    {
89
        $this->dispatchMapEvent('onEndMapEnd', $params);
90
    }
91
92
    /**
93
     * Dispatch map event.
94
     *
95
     * @param $eventName
96
     * @param $params
97
     */
98
    protected function dispatchMapEvent($eventName, $params)
99
    {
100
        $map = $this->mapStorage->getMap($params['map']['uid']);
101
102
        $this->dispatch(
103
            $eventName,
104
            [
105
                $params['count'],
106
                $params['time'],
107
                $params['restarted'],
108
                $map,
109
            ]
110
        );
111
    }
112
113
}