|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace IrishDan\NotificationBundle\Formatter; |
|
4
|
|
|
|
|
5
|
|
|
use IrishDan\NotificationBundle\Message\Message; |
|
6
|
|
|
use IrishDan\NotificationBundle\Notification\NotificationInterface; |
|
7
|
|
|
use IrishDan\NotificationBundle\Textable; |
|
8
|
|
|
|
|
9
|
|
|
class NexmoDataFormatter extends BaseFormatter implements MessageFormatterInterface |
|
10
|
|
|
{ |
|
11
|
|
|
protected $nexmoConfiguration; |
|
12
|
|
|
|
|
13
|
|
|
public function __construct(array $nexmoConfiguration = []) |
|
14
|
|
|
{ |
|
15
|
|
|
$this->nexmoConfiguration = $nexmoConfiguration; |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function format(NotificationInterface $notification) |
|
19
|
|
|
{ |
|
20
|
|
|
$message = new Message(); |
|
21
|
|
|
$notificationData = $notification->getDataArray(); |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
// The User/Notifiable must implement Textable interface in order to receive SMSs |
|
24
|
|
|
$notifiable = $notification->getNotifiable(); |
|
25
|
|
|
if (!$notifiable instanceof Textable) { |
|
26
|
|
|
throw new \RuntimeException('Notifiable does not implement Texable interface'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
// Build the dispatch data array. |
|
30
|
|
|
$dispatchData = [ |
|
31
|
|
|
'to' => $notifiable->getNumber(), |
|
32
|
|
|
'from' => empty($this->nexmoConfiguration['from']) ? '' : $this->nexmoConfiguration['from'], |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
// Build the message data array. |
|
36
|
|
|
$messageData = []; |
|
37
|
|
|
// @TODO: Works but not when body is dynamic?? |
|
38
|
|
|
$messageData['body'] = 'A Hoi hoi! Marcus!'; |
|
39
|
|
|
// if (!empty($this->twig) && $notification->getTemplate()) { |
|
|
|
|
|
|
40
|
|
|
// $messageData['body'] = $this->renderTwigTemplate( |
|
|
|
|
|
|
41
|
|
|
// $notificationData, |
|
42
|
|
|
// $notifiable, |
|
43
|
|
|
// $notification->getTemplate() |
|
|
|
|
|
|
44
|
|
|
// ); |
|
45
|
|
|
// } |
|
46
|
|
|
|
|
47
|
|
|
$message->setDispatchData($dispatchData); |
|
48
|
|
|
$message->setMessageData($messageData); |
|
49
|
|
|
|
|
50
|
|
|
return $message; |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.