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

EventBase   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 5
Bugs 0 Features 3
Metric Value
wmc 6
c 5
b 0
f 3
lcom 1
cbo 1
dl 0
loc 75
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
getEventName() 0 1 ?
A getPayload() 0 4 1
A getDelivery() 0 4 1
A getRepository() 0 4 1
A getSender() 0 4 1
A __sleep() 0 4 1
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