Elitbuzz::parseResponse()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Sarahman\SmsService\Providers;
4
5
use Sarahman\SmsService\Response;
6
7
class Elitbuzz extends BaseProvider
8
{
9
    public function getUsername()
10
    {
11
        return $this->config['api_key'];
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
            'contacts' => $recipient,
24
            'msg'      => $message,
25
        ];
26
    }
27
28
    public function getValidationRules()
29
    {
30
        return [
31
            'api_key'  => 'required',
32
            'type'     => 'required',
33
            'senderid' => 'required',
34
            'contacts' => 'required|regex:/^8801[3456789]\d{8}$/',
35
            'msg'      => 'required',
36
        ];
37
    }
38
39
    public function parseResponse($response)
40
    {
41
        preg_match('/^SMS SUBMITTED\: ID \- .*$/i', $response, $matches);
42
43
        return new Response(is_array($matches) && array_key_exists(0, $matches), $response);
44
    }
45
}
46