OutboundSMSRequest::uri()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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)
0 ignored issues
show
Unused Code introduced by
The parameter $senderName is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

32
    public function __construct($message, $recipientNumber, $senderNumber, /** @scrutinizer ignore-unused */ $senderName = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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