MessageEcho::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 9
cts 9
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Model\Callback;
6
7
class MessageEcho extends Message
8
{
9
    /**
10
     * @var bool
11
     */
12
    protected $isEcho;
13
14
    /**
15
     * @var int|null
16
     */
17
    protected $appId;
18
19
    /**
20
     * @var string|null
21
     */
22
    protected $metadata;
23
24
    /**
25
     * MessageEcho constructor.
26
     */
27 1
    public function __construct(
28
        bool $isEcho,
29
        ?int $appId,
30
        string $messageId,
31
        ?string $metadata = null,
32
        ?string $text = null,
33
        ?string $quickReply = null,
34
        array $attachments = []
35
    ) {
36 1
        parent::__construct($messageId, $text, $quickReply, $attachments);
37
38 1
        $this->isEcho = $isEcho;
39 1
        $this->appId = $appId;
40 1
        $this->metadata = $metadata;
41 1
    }
42
43 1
    public function isEcho(): bool
44
    {
45 1
        return $this->isEcho;
46
    }
47
48 1
    public function getAppId(): ?int
49
    {
50 1
        return $this->appId;
51
    }
52
53 1
    public function getMetadata(): ?string
54
    {
55 1
        return $this->metadata;
56
    }
57
58
    /**
59
     * @return \Kerox\Messenger\Model\Callback\MessageEcho
60
     */
61 1
    public static function create(array $callbackData)
62
    {
63 1
        $appId = $callbackData['app_id'] ?? null;
64 1
        $metadata = $callbackData['metadata'] ?? null;
65 1
        $text = $callbackData['text'] ?? null;
66 1
        $quickReply = $callbackData['quick_reply']['payload'] ?? null;
67 1
        $attachments = $callbackData['attachments'] ?? [];
68
69 1
        return new self(
70 1
            true,
71
            $appId,
72 1
            $callbackData['mid'],
73
            $metadata,
74
            $text,
75
            $quickReply,
76
            $attachments
77
        );
78
    }
79
}
80