NotificationResponse::getRawResponsePayload()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Level51\OneSignal;
4
5
/**
6
 * Class NotificationResponse
7
 *
8
 * @see     https://documentation.onesignal.com/reference/create-notification#results---create-notification
9
 *
10
 * @package Level51\OneSignal
11
 */
12
class NotificationResponse
13
{
14
15
    const ACTION_CREATE = 'create';
16
17
    /**
18
     * @var string
19
     */
20
    private $action;
21
22
    /**
23
     * @var array
24
     */
25
    private $rawResponsePayload;
26
27
    /**
28
     * Notification response wrapper object.
29
     *
30
     * @param array       $raw Raw response payload
31
     * @param string|null $action
32
     */
33 7
    public function __construct(array $raw, $action = null)
34
    {
35 7
        if ($action === null) {
36 7
            $action = self::ACTION_CREATE;
37
        }
38
39 7
        $this->action = $action;
40 7
        $this->rawResponsePayload = $raw;
41 7
    }
42
43 2
    public function isError()
44
    {
45 2
        return !empty($this->rawResponsePayload['errors']);
46
    }
47
48 2
    public function getId()
49
    {
50 2
        return $this->rawResponsePayload['id'] ?? null;
51
    }
52
53 2
    public function getRecipientsCount()
54
    {
55 2
        return $this->rawResponsePayload['recipients'] ?? null;
56
    }
57
58 1
    public function getAction()
59
    {
60 1
        return $this->action;
61
    }
62
63 1
    public function getRawResponsePayload()
64
    {
65 1
        return $this->rawResponsePayload;
66
    }
67
}
68