NotificationResponse   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 54
ccs 16
cts 16
cp 1
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getId() 0 3 1
A getAction() 0 3 1
A isError() 0 3 1
A getRecipientsCount() 0 3 1
A getRawResponsePayload() 0 3 1
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