PostbackEvent   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 53
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getTimestamp() 0 4 1
A getPostback() 0 4 1
A getName() 0 4 1
A create() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Event;
6
7
use Kerox\Messenger\Model\Callback\Postback;
8
9
class PostbackEvent extends AbstractEvent
10
{
11
    public const NAME = 'postback';
12
13
    /**
14
     * @var int
15
     */
16
    protected $timestamp;
17
18
    /**
19
     * @var \Kerox\Messenger\Model\Callback\Postback
20
     */
21
    protected $postback;
22
23
    /**
24
     * PostbackEvent constructor.
25
     */
26 3
    public function __construct(string $senderId, string $recipientId, int $timestamp, Postback $postback)
27
    {
28 3
        parent::__construct($senderId, $recipientId);
29
30 3
        $this->timestamp = $timestamp;
31 3
        $this->postback = $postback;
32 3
    }
33
34 1
    public function getTimestamp(): int
35
    {
36 1
        return $this->timestamp;
37
    }
38
39 3
    public function getPostback(): Postback
40
    {
41 3
        return $this->postback;
42
    }
43
44 1
    public function getName(): string
45
    {
46 1
        return self::NAME;
47
    }
48
49
    /**
50
     * @return \Kerox\Messenger\Event\PostbackEvent
51
     */
52 2
    public static function create(array $payload): self
53
    {
54 2
        $senderId = $payload['sender']['id'];
55 2
        $recipientId = $payload['recipient']['id'];
56 2
        $timestamp = $payload['timestamp'];
57 2
        $postback = Postback::create($payload['postback']);
58
59 2
        return new static($senderId, $recipientId, $timestamp, $postback);
60
    }
61
}
62