Avstelecomsms   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPhone() 0 6 2
A __construct() 0 4 1
A send() 0 22 3
1
<?php
2
3
namespace Tematech\Avstelecomsms;
4
5
use Exception;
6
use Illuminate\Support\Facades\Http;
7
use GuzzleHttp\Exception\GuzzleException;
8
9
class Avstelecomsms
10
{
11
    protected $client;
12
13
    public function __construct()
14
    {
15
        //
16
    }
17
    /**
18
     * Undocumented function
19
     *
20
     * @param string $phone E.164 2376XXXXXXX
21
     * @param string $message
22
     * @return bool
23
     */
24
    public function send(string $phone, string $message)
25
    {
26
        $timestamp = time();
27
        try {
28
            $response = Http::post('http://54.37.231.5:8090/bulksms', [
29
                'id'            => config('avstelecomsms.id'),
30
                'timestamp'     => $timestamp,
31
                'signature'     => hash_hmac('SHA1', config('avstelecomsms.token') . $timestamp, config('avstelecomsms.secret')),
32
                'phonenumber'   => $this->getPhone($phone),
33
                'sms'           => $message,
34
                'schedule'      => ''
35
            ]);
36
            $data = $response->json();
37
           
38
            if ($data['status'] != 200) {
39
                return false;
40
            }
41
            return true;
42
        } catch (Exception $e) {
43
            return false;
44
        }
45
    }
46
47
    private function getPhone(string $phone): string
48
    {
49
        if (strlen($phone) == 9)
50
            return '237' . $phone;
51
        return $phone;
52
    }
53
}
54