BroadcastRequest::buildBody()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 6
cts 6
cp 1
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Request;
6
7
use Kerox\Messenger\Model\Message;
8
use Kerox\Messenger\SendInterface;
9
10
/**
11
 * @deprecated Since version 3.2.0 and will be removed in version 4.0.0.
12
 */
13
class BroadcastRequest extends AbstractRequest
14
{
15
    public const REQUEST_TYPE_MESSAGE = 'message';
16
    public const REQUEST_TYPE_ACTION = 'action';
17
18
    /**
19
     * @var string|\Kerox\Messenger\Model\Message|null
20
     */
21
    protected $message;
22
23
    /**
24
     * @var string|null
25
     */
26
    protected $messageCreativeId;
27
28
    /**
29
     * @var string|null
30
     */
31
    protected $notificationType;
32
33
    /**
34
     * @var string|null
35
     */
36
    protected $tag;
37
38
    /**
39
     * @var string
40
     */
41
    protected $messagingType;
42
43
    /**
44
     * Request constructor.
45
     */
46 2
    public function __construct(
47
        string $pageToken,
48
        ?Message $message = null,
49
        ?string $messageCreativeId = null,
50
        array $options = []
51
    ) {
52 2
        parent::__construct($pageToken);
53
54 2
        $this->message = $message;
55 2
        $this->messageCreativeId = $messageCreativeId;
56 2
        $this->notificationType = $options[SendInterface::OPTION_NOTIFICATION_TYPE] ?? null;
57 2
        $this->tag = $options[SendInterface::OPTION_TAG] ?? null;
58 2
    }
59
60 2
    protected function buildHeaders(): array
61
    {
62
        return [
63 2
            'Content-Type' => 'application/json',
64
        ];
65
    }
66
67 2
    protected function buildBody(): array
68
    {
69
        $body = [
70
            'messages' => [
71 2
                $this->message,
72
            ],
73 2
            'message_creative_id' => $this->messageCreativeId,
74 2
            'notification_type' => $this->notificationType,
75 2
            'tag' => $this->tag,
76
        ];
77
78 2
        return array_filter($body);
79
    }
80
}
81