Chikka   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 63
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B send() 0 31 2
A balance() 0 4 1
1
<?php
2
namespace ridvanbaluyos\sms\providers;
3
4
use ridvanbaluyos\sms\SmsProviderServicesInterface as SmsProviderServicesInterface;
5
use ridvanbaluyos\sms\Sms as Sms;
6
use Noodlehaus\Config as Config;
7
use Exception as Exception;
8
9
/**
10
 * Class Chikka
11
 * @package ridvanbaluyos\sms\providers
12
 */
13
class Chikka extends Sms implements SmsProviderServicesInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    protected $className;
19
20
    /**
21
     * Chikka constructor.
22
     */
23
    public function __construct()
24
    {
25
        $this->className = substr(get_called_class(), strrpos(get_called_class(), '\\') + 1);
26
    }
27
28
    /**
29
     * This function sends the SMS.
30
     *
31
     * @param $phoneNumber
32
     * @param $message
33
     * @return string
34
     */
35
    public function send($phoneNumber, $message)
36
    {
37
        try {
38
            $conf = Config::load(__DIR__ . '/../config/providers.json')[$this->className];
39
            $messageId = $this->generateMessageId(32);
40
41
            $query = array(
42
                'message_type' => 'SEND',
43
                'mobile_number' => $phoneNumber,
44
                'shortcode' => $conf['shortcode'],
45
                'message_id' => $messageId,
46
                'message' => $message,
47
                'client_id' => $conf['client_id'],
48
                'secret_key' => $conf['secret_key'],
49
            );
50
51
            $query = http_build_query($query);
52
            $ch = curl_init();
53
            curl_setopt($ch, CURLOPT_URL, $conf['url']);
54
            curl_setopt($ch, CURLOPT_POST, count($query));
55
            curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
56
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
57
            $result = curl_exec($ch);
58
            curl_close($ch);
59
60
            $result = json_decode($result);
61
            return $this->response($result->status, $result, null, $this->className);
62
        } catch (Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
63
64
        }
65
    }
66
67
    /**
68
     * This function checks the account balance.
69
     *
70
     */
71
    public function balance()
72
    {
73
        return $this->response(404, [], $this->className . ' currently does not support this feature.', $this->className);
74
    }
75
}
76