Completed
Push — master ( 8e0ded...b5dffc )
by Romain
10s
created

BroadcastRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 84
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A buildBody() 0 12 1
A buildHeaders() 0 4 1
A __construct() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Request;
6
7
use Kerox\Messenger\Model\Message;
8
9
class BroadcastRequest extends AbstractRequest
10
{
11
    public const REQUEST_TYPE_MESSAGE = 'message';
12
    public const REQUEST_TYPE_ACTION = 'action';
13
14
    public const MESSAGING_TYPE_RESPONSE = 'RESPONSE';
15
    public const MESSAGING_TYPE_UPDATE = 'UPDATE';
16
    public const MESSAGING_TYPE_MESSAGE_TAG = 'MESSAGE_TAG';
17
    public const MESSAGING_TYPE_NON_PROMOTIONAL_SUBSCRIPTION = 'NON_PROMOTIONAL_SUBSCRIPTION';
18
19
    /**
20
     * @var null|string|\Kerox\Messenger\Model\Message
21
     */
22
    protected $message;
23
24
    /**
25
     * @var null|string
26
     */
27
    protected $messageCreativeId;
28
29
    /**
30
     * @var null|string
31
     */
32
    protected $notificationType;
33
34
    /**
35
     * @var null|string
36
     */
37
    protected $tag;
38
39
    /**
40
     * @var string
41
     */
42
    protected $messagingType;
43
44
    /**
45
     * Request constructor.
46
     *
47
     * @param string                              $pageToken
48
     * @param \Kerox\Messenger\Model\Message|null $message
49
     * @param string|null                         $messageCreativeId
50
     * @param string|null                         $notificationType
51
     * @param string|null                         $tag
52
     */
53
    public function __construct(
54
        string $pageToken,
55
        ?Message $message = null,
56
        ?string $messageCreativeId = null,
57
        ?string $notificationType = null,
58
        ?string $tag = null
59
    ) {
60
        parent::__construct($pageToken);
61
62
        $this->message = $message;
63
        $this->messageCreativeId = $messageCreativeId;
64
        $this->notificationType = $notificationType;
65
        $this->tag = $tag;
66
    }
67
68
    /**
69
     * @return array
70
     */
71
    protected function buildHeaders(): array
72
    {
73
        return [
74
            'Content-Type' => 'application/json',
75
        ];
76
    }
77
78
    /**
79
     * @return array
80
     */
81
    protected function buildBody(): array
82
    {
83
        $body = [
84
            'messages'            => [
85
                $this->message,
86
            ],
87
            'message_creative_id' => $this->messageCreativeId,
88
            'notification_type'   => $this->notificationType,
89
            'tag'                 => $this->tag,
90
        ];
91
92
        return array_filter($body);
93
    }
94
}
95