Test Setup Failed
Push — master ( e800d8...2251b9 )
by Syed Abidur
02:18
created

SslPlus::mapParams()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 3
nop 3
dl 0
loc 12
rs 10
1
<?php
2
3
namespace Sarahman\SmsService\Providers;
4
5
use Sarahman\SmsService\Response;
6
7
class SslPlus extends BaseProvider
8
{
9
    public function getUsername()
10
    {
11
        return $this->config['api_token'];
12
    }
13
14
    public function mapParams($recipient, $message, array $params = [])
15
    {
16
        if (!preg_match($this->recipientPattern, $recipient, $matches)) {
17
            return [];
18
        }
19
20
        $recipient = '880'.$matches[3];
21
22
        return [
23
            'csms_id' => isset($params['csms_id']) ? $params['csms_id'] : rand(100000, 999999),
24
            'msisdn'  => $recipient,
25
            'sms'     => $message,
26
        ];
27
    }
28
29
    public function getValidationRules()
30
    {
31
        return [
32
            'api_token' => 'required',
33
            'sid'       => 'required',
34
            'csms_id'   => 'required',
35
            'msisdn'    => 'required|regex:/^8801[3456789]\d{8}$/',
36
            'sms'       => 'required',
37
        ];
38
    }
39
40
    public function parseResponse($response)
41
    {
42
        $parsedResponse = json_decode($response);
43
44
        return new Response('success' === strtolower($parsedResponse->status) && 200 === $parsedResponse->status_code, $response);
45
    }
46
}
47