Banglalink::getUsername()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

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
rs 10
1
<?php
2
3
namespace Sarahman\SmsService\Providers;
4
5
use Sarahman\SmsService\Response;
6
7
class Banglalink extends BaseProvider
8
{
9
    public function getUsername()
10
    {
11
        return $this->config['userID'];
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
            'msisdn'  => $recipient,
24
            'message' => preg_replace('/[^a-zA-Z0-9\.@!?&\-,%\(\):\"]/', ' ', $message),
25
        ];
26
    }
27
28
    public function getValidationRules()
29
    {
30
        return [
31
            'userID'  => 'required',
32
            'passwd'  => 'required',
33
            'msisdn'  => 'required|regex:/^8801[3456789]\d{8}$/',
34
            'message' => 'required',
35
        ];
36
    }
37
38
    public function parseResponse($response)
39
    {
40
        preg_match('/^(success count \: ([0-9])*) and (fail count \: ([0-9])*)/i', $response, $matches);
41
42
        return new Response(is_array($matches) && array_key_exists(2, $matches) && $matches[2] == 1, $response);
43
    }
44
}
45