EventBase::getPayload()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Smalot\Github\Webhook\Event;
4
5
use Smalot\Github\Webhook\Model\ModelBase;
6
use Symfony\Component\EventDispatcher\Event;
7
8
/**
9
 * Class EventBase
10
 * @package Smalot\Github\Webhook\Event
11
 */
12
abstract class EventBase extends Event
13
{
14
    /**
15
     * @var string
16
     */
17
    protected $eventName;
18
19
    /**
20
     * @var string
21
     */
22
    protected $payload;
23
24
    /**
25
     * @var ModelBase
26
     */
27
    protected $model;
28
29
    /**
30
     * @var string
31
     */
32
    protected $delivery;
33
34
    /**
35
     * EventBase constructor.
36
     * @param string $eventName
37
     * @param string $payload
38
     * @param string $delivery
39
     */
40
    public function __construct($eventName, $payload, $delivery = null)
41
    {
42
        $this->eventName = $eventName;
43
        $this->payload = $payload;
44
        $this->delivery = $delivery;
45
46
        $payload = json_decode($this->payload, true);
47
        $className = $this->getClassModel();
48
        $this->model = new $className($payload);
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    public function getEventName()
55
    {
56
        return $this->eventName;
57
    }
58
59
    /**
60
     * @return string
61
     */
62
    public function getPayload()
63
    {
64
        return $this->payload;
65
    }
66
67
    /**
68
     * @return ModelBase
69
     */
70
    public function getModel()
71
    {
72
        return $this->model;
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    abstract protected function getClassModel();
79
}
80