EventBase::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 11
rs 9.4285
cc 1
eloc 8
nc 1
nop 4
1
<?php
2
3
namespace Smalot\Bitbucket\Webhook\Event;
4
5
use Smalot\Bitbucket\Webhook\Model\ModelBase;
6
use Symfony\Component\EventDispatcher\Event;
7
8
/**
9
 * Class EventBase
10
 * @package Smalot\Bitbucket\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 int
31
     */
32
    protected $attemptCount;
33
34
    /**
35
     * @var string
36
     */
37
    protected $requestUuid;
38
39
    /**
40
     * EventBase constructor.
41
     * @param string $eventName
42
     * @param string $payload
43
     * @param int $attemptCount
44
     * @param string $requestUuid
45
     */
46
    public function __construct($eventName, $payload, $attemptCount, $requestUuid)
47
    {
48
        $this->eventName = $eventName;
49
        $this->payload = $payload;
50
        $this->attemptCount = $attemptCount;
51
        $this->requestUuid = $requestUuid;
52
53
        $payload = json_decode($this->payload, true);
54
        $className = $this->getClassModel();
55
        $this->model = new $className($payload);
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getEventName()
62
    {
63
        return $this->eventName;
64
    }
65
66
    /**
67
     * @return string
68
     */
69
    public function getPayload()
70
    {
71
        return $this->payload;
72
    }
73
74
    /**
75
     * @return int
76
     */
77
    public function getAttemptCount()
78
    {
79
        return $this->attemptCount;
80
    }
81
82
    /**
83
     * @return string
84
     */
85
    public function getRequestUuid()
86
    {
87
        return $this->requestUuid;
88
    }
89
90
    /**
91
     * @return ModelBase
92
     */
93
    public function getModel()
94
    {
95
        return $this->model;
96
    }
97
98
    /**
99
     * @return string
100
     */
101
    abstract protected function getClassModel();
102
}
103