Passed
Push — master ( e59495...facc33 )
by Isaac
02:07
created

OutboundSMSRequest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
dl 0
loc 87
ccs 18
cts 21
cp 0.8571
rs 10
c 0
b 0
f 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A method() 0 3 1
A throwsExceptionIfEmpty() 0 8 3
A __construct() 0 13 3
A options() 0 5 1
A uri() 0 3 1
1
<?php
2
3
namespace Mediumart\Orange\SMS\Http\Requests;
4
5
use Exception;
6
use Mediumart\Orange\SMS\Http\SMSClientRequest;
7
8
class OutboundSMSRequest extends SMSClientRequest
9
{
10
    /**
11
     * Request body
12
     *
13
     * @var array
14
     */
15
    protected $body;
16
17
    /**
18
     * Recipient number
19
     *
20
     * @var string
21
     */
22
    protected $sender;
23
24
    /**
25
     * OutboundSMSObjectRequest constructor.
26
     * @param $message
27
     * @param $recipientNumber
28
     * @param $senderNumber
29
     * @param $senderName
30
     * @throws \Exception
31
     */
32 1
    public function __construct($message, $recipientNumber, $senderNumber, $senderName = null)
33
    {
34 1
        $this->throwsExceptionIfEmpty($recipientNumber, $senderNumber);
35
36 1
        $this->body = ['outboundSMSMessageRequest' => [
37 1
               'address' => 'tel:'.$this->normalizePhoneNumber($recipientNumber),
38 1
               'senderAddress' => $this->sender = 'tel:'.$this->normalizePhoneNumber($senderNumber),
39 1
               'outboundSMSTextMessage' => [ 'message' => $message ?: '']
40
           ]
41
        ];
42
43 1
        if ($senderName) {
44
            $this->body['outboundSMSMessageRequest']['senderName'] = urlencode($senderName);
45
        }
46 1
    }
47
48
    /**
49
     * @inherit
50
     *
51
     * @return string
52
     */
53 1
    public function method()
54
    {
55 1
        return 'POST';
56
    }
57
58
    /**
59
     * @inherit
60
     *
61
     * @return string
62
     * @throws \Exception
63
     */
64 1
    public function uri()
65
    {
66 1
        return static::BASE_URI."/smsmessaging/v1/outbound/".urlencode($this->sender)."/requests";
67
    }
68
69
    /**
70
     * @inherit
71
     *
72
     * @return array
73
     */
74 1
    public function options()
75
    {
76
        return [
77 1
            'headers' => ["Content-Type" => "Application/json"],
78 1
            'body' => json_encode($this->body)
79
        ];
80
    }
81
82
    /**
83
     * @param $recipientNumber
84
     * @param $senderNumber
85
     * @throws \Exception
86
     */
87 1
    private function throwsExceptionIfEmpty($recipientNumber, $senderNumber)
88
    {
89 1
        if (empty($senderNumber)) {
90
            throw new Exception('Missing Sender number');
91
        }
92
93 1
        if (empty($recipientNumber)) {
94
            throw new Exception('Missing Recipient number');
95
        }
96 1
    }
97
}
98