Completed
Pull Request — master (#6)
by Mark
09:54 queued 07:36
created

IonicPushMessage::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace NotificationChannels\IonicPushNotifications;
4
5
class IonicPushMessage
6
{
7
    /** @var string */
8
    public $sendTo = 'tokens';
9
10
    /** @var string */
11
    public $profile;
12
13
    /** @var string */
14
    public $title = '';
15 2
16
    /** @var string */
17 2
    public $message = '';
18
19
    /** @var string */
20
    public $sound = '';
21
22
    /** @var array */
23 2
    public $payload = [];
24
25 2
    /** @var array */
26 2
    public $iosData = [];
27
28
    /** @var array */
29
    public $androidData = [];
30
31 2
    /**
32
     * @param array $data
0 ignored issues
show
Bug introduced by
There is no parameter named $data. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
33 2
     *
34
     * @return static
35
     */
36
    public static function create($profile)
37
    {
38
        return new static($profile);
39
    }
40
41
    /**
42
     * @param string $profile
43
     */
44
    public function __construct($profile)
45
    {
46
        $this->profile = $profile;
47
    }
48
49
    /**
50
     * Set the method of targeting users - tokens (default), user_ids, or emails.
51
     *
52
     * @param  string  $profile
0 ignored issues
show
Bug introduced by
There is no parameter named $profile. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
53
     *
54
     * @return $this
55
     */
56
    public function sendTo($sendTo)
57
    {
58
        $this->sendTo = $sendTo;
59
60
        return $this;
61
    }
62
63
    /**
64
     * Set the title.
65
     *
66
     * @param  string  $title
67
     *
68
     * @return $this
69
     */
70
    public function title($title)
71
    {
72
        $this->title = $title;
73
74
        return $this;
75
    }
76
77
    /**
78
     * Set the message.
79
     *
80
     * @param  string  $message
81
     *
82
     * @return $this
83
     */
84
    public function message($message)
85
    {
86
        $this->message = $message;
87
88
        return $this;
89
    }
90
91
    /**
92
     * Set the security sound to use.
93
     *
94
     * @param  string  $sound
95
     *
96
     * @return $this
97
     */
98
    public function sound($sound)
99
    {
100
        $this->sound = $sound;
101
102
        return $this;
103
    }
104
105
    /**
106
     * Send custom key/value data with your notifications.
107
     *
108
     * @param  array  $payload
109
     *
110
     * @return $this
111
     */
112
    public function payload($payload)
113
    {
114
        $this->payload = $payload;
115
116
        return $this;
117
    }
118
119
    /**
120
     * Dynamically add device specific data.
121
     *
122
     * @param string $method
123
     * @param array  $args
124
     *
125
     * @return object
126
     */
127
    public function __call($method, $args)
128
    {
129
        if (substr($method, 0, 3) == 'ios') {
130
            $key = snake_case(substr($method, 3));
131
132
            $this->iosData[$key] = $args[0];
133
        } elseif (substr($method, 0, 7) == 'android') {
134
            $key = snake_case(substr($method, 7));
135
136
            $this->androidData[$key] = $args[0];
137
        }
138
139
        return $this;
140
    }
141
142
    /**
143
     * Get the method we want to use to send messages.
144
     *
145
     * @return string
146
     */
147
    public function getSendToType()
148
    {
149
        return $this->sendTo;
150
    }
151
152
    /**
153
     * @return array
154
     */
155
    public function toArray()
156
    {
157
        $data = [
158
            'profile' => $this->profile,
159
            'notification' => [
160
                'message' => $this->message,
161
            ],
162
        ];
163
164
        if (! empty($this->title)) {
165
            $data['notification']['title'] = $this->title;
166
        }
167
168
        if (! empty($this->sound)) {
169
            $data['notification']['sound'] = $this->sound;
170
        }
171
172
        if (! empty($this->iosData)) {
173
            $data['notification']['ios'] = $this->iosData;
174
        }
175
176
        if (! empty($this->androidData)) {
177
            $data['notification']['android'] = $this->androidData;
178
        }
179
180
        if (! empty($this->payload)) {
181
            $data['notification']['payload'] = $this->payload;
182
        }
183
184
        return $data;
185
    }
186
}
187