Robi   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getValidationRules() 0 8 1
A getUsername() 0 3 1
A parseResponse() 0 10 2
A mapParams() 0 11 2
1
<?php
2
3
namespace Sarahman\SmsService\Providers;
4
5
use Exception;
6
use Illuminate\Support\Facades\Log;
7
use Sarahman\SmsService\Response;
8
use SimpleXMLElement;
9
10
class Robi extends BaseProvider
11
{
12
    public function getUsername()
13
    {
14
        return $this->config['Username'];
15
    }
16
17
    public function mapParams($recipient, $message, array $params = [])
18
    {
19
        if (!preg_match($this->recipientPattern, $recipient, $matches)) {
20
            return [];
21
        }
22
23
        $recipient = '880'.$matches[3];
24
25
        return [
26
            'To'      => $recipient,
27
            'Message' => $message,
28
        ];
29
    }
30
31
    public function getValidationRules()
32
    {
33
        return [
34
            'Username' => 'required',
35
            'Password' => 'required',
36
            'From'     => 'required|regex:/^8801[3456789]\d{8}$/',
37
            'To'       => 'required|regex:/^8801[3456789]\d{8}$/',
38
            'Message'  => 'required',
39
        ];
40
    }
41
42
    public function parseResponse($response)
43
    {
44
        try {
45
            $xmlElement = new SimpleXMLElement($response);
46
47
            return new Response(0 == (string) $xmlElement->ErrorCode, $response);
48
        } catch (Exception $exception) {
49
            Log::error($exception);
50
51
            return new Response(false, 'Robi did not respond!');
52
        }
53
    }
54
}
55