Completed
Push — master ( d4e6df...8a38f1 )
by Sebastien
02:13
created

EventBase::__sleep()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
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 Symfony\Component\EventDispatcher\Event;
6
7
/**
8
 * Class EventBase
9
 * @package Smalot\Github\Webhook\Event
10
 */
11
abstract class EventBase extends Event
12
{
13
    /**
14
     * @var string
15
     */
16
    protected $eventName;
17
18
    /**
19
     * @var array
20
     */
21
    protected $payload;
22
23
    /**
24
     * @var string
25
     */
26
    protected $delivery;
27
28
    /**
29
     * EventBase constructor.
30
     * @param string $eventName
31
     * @param string $payload
32
     * @param string $delivery
33
     */
34
    public function __construct($eventName, $payload, $delivery = null)
35
    {
36
        $this->eventName = $eventName;
37
        $this->payload = (array) json_decode($payload, true);
38
        $this->delivery = $delivery;
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    abstract public function getEventName();
45
46
    /**
47
     * @return array
48
     */
49
    public function getPayload()
50
    {
51
        return $this->payload;
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getDelivery()
58
    {
59
        return $this->delivery;
60
    }
61
62
    /**
63
     * @return array
64
     */
65
    public function getRepository()
66
    {
67
        return $this->payload['repository'];
68
    }
69
70
    /**
71
     * @return array
72
     */
73
    public function getSender()
74
    {
75
        return $this->payload['sender'];
76
    }
77
78
    /**
79
     * @return array
80
     */
81
    public function __sleep()
82
    {
83
        return array_diff(array_keys(get_object_vars($this)), array('dispatcher'));
84
    }
85
}
86