Plivo   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 15%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 49
ccs 3
cts 20
cp 0.15
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 15 2
A searchNumber() 0 4 1
A buyNumber() 0 8 1
A sellNumber() 0 8 1
1
<?php
2
3
namespace LeadThread\Sms\Drivers;
4
5
use Plivo\RestAPI as Service;
6
use LeadThread\Sms\Drivers\Driver;
7
use LeadThread\Sms\Interfaces\PhoneSearchParams;
8
use LeadThread\Sms\Responses\Plivo as PlivoResponse;
9
10
class Plivo extends Driver
11
{
12
13
    protected $handle;
14
15 18
    public function __construct($auth_id, $auth_token)
16
    {
17 18
        $this->handle = new Service($auth_id, $auth_token);
18 18
    }
19
20
    public function send($msg, $to, $from, $callback = null)
21
    {
22
        if (!empty($callback)) {
23
            throw new \Exception("Callback URLs are not implemented for Plivo", 1);
24
        }
25
26
        $params = [
27
            'src'  => $from,
28
            'dst'  => $to,
29
            'text' => $msg,
30
            'type' => 'sms'
31
        ];
32
33
        return new PlivoResponse($this->handle->send_message($params));
34
    }
35
36
    public function searchNumber(PhoneSearchParams $search)
37
    {
38
        return new PlivoResponse($this->handle->search_phone_numbers($search->toArray()));
39
    }
40
41
    public function buyNumber($phone)
42
    {
43
        $params = [
44
            'number' => $phone
45
        ];
46
47
        return new PlivoResponse($this->handle->buy_phone_number($params));
48
    }
49
50
    public function sellNumber($phone)
51
    {
52
        $phone = str_replace("+", "", $phone);
53
        $params = [
54
            'number' => $phone
55
        ];
56
        return new PlivoResponse($this->handle->unrent_number($params));
57
    }
58
}
59