EventBase   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getEventName() 0 4 1
A getPayload() 0 4 1
A getModel() 0 4 1
getClassModel() 0 1 ?
A __construct() 0 10 1
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