1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\FortySixElks; |
4
|
|
|
|
5
|
|
|
use NotificationChannels\FortySixElks\Exceptions\CouldNotSendNotification; |
6
|
|
|
|
7
|
|
|
class FortySixElksSMS extends FortySixElksMedia implements FortySixElksMediaInterface |
8
|
|
|
{ |
9
|
|
|
const ENDPOINT = 'https://api.46elks.com/a1/SMS'; |
10
|
|
|
|
11
|
|
|
protected array $form_params; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* FortySixElksSMS constructor. |
15
|
|
|
*/ |
16
|
|
|
public function __construct() |
17
|
|
|
{ |
18
|
|
|
$this->form_params = []; |
19
|
|
|
|
20
|
|
|
return parent::__construct(); |
|
|
|
|
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @return $this |
25
|
|
|
*/ |
26
|
|
|
public function send() |
27
|
|
|
{ |
28
|
|
|
try { |
29
|
|
|
$response = $this->client->request('POST', self::ENDPOINT, [ |
|
|
|
|
30
|
|
|
'form_params' => array_merge( |
31
|
|
|
$this->form_params, |
32
|
|
|
[ |
33
|
|
|
'from' => $this->from, |
34
|
|
|
'to' => $this->phone_number, |
35
|
|
|
'message' => $this->getContent(), |
36
|
|
|
] |
37
|
|
|
), |
38
|
|
|
]); |
39
|
|
|
} catch (\GuzzleHttp\Exception\BadResponseException $e) { |
40
|
|
|
$response = $e->getResponse(); |
41
|
|
|
|
42
|
|
|
throw CouldNotSendNotification::serviceRespondedWithAnError( |
43
|
|
|
$response->getBody()->getContents(), |
44
|
|
|
$response->getStatusCode() |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $this; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return array |
53
|
|
|
*/ |
54
|
|
|
public function prepareParams(string $key, mixed $value): FortySixElksSMS |
55
|
|
|
{ |
56
|
|
|
$this->form_params[$key] = $value; |
57
|
|
|
|
58
|
|
|
return $this; |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return void |
63
|
|
|
*/ |
64
|
|
|
public function flash(string $value = 'yes'): FortySixElksSMS |
65
|
|
|
{ |
66
|
|
|
self::prepareParams(key: 'flash', value: $value); |
|
|
|
|
67
|
|
|
|
68
|
|
|
return $this; |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param string $value |
73
|
|
|
* |
74
|
|
|
* @return FortySixElksSMS |
75
|
|
|
*/ |
76
|
|
|
public function dry(string $value = 'yes'): FortySixElksSMS |
77
|
|
|
{ |
78
|
|
|
self::prepareParams(key: 'dryrun', value: $value); |
|
|
|
|
79
|
|
|
|
80
|
|
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param string $url |
85
|
|
|
* |
86
|
|
|
* @return FortySixElksSMS |
87
|
|
|
*/ |
88
|
|
|
public function whenDelivered(string $url): FortySixElksSMS |
89
|
|
|
{ |
90
|
|
|
self::prepareParams(key: 'whendelivered', value: $url); |
|
|
|
|
91
|
|
|
|
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return FortySixElksSMS |
97
|
|
|
*/ |
98
|
|
|
public function dontLog(): FortySixElksSMS |
99
|
|
|
{ |
100
|
|
|
self::prepareParams(key: 'dontlog', value: 'message'); |
|
|
|
|
101
|
|
|
|
102
|
|
|
return $this; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.