CynSMSAPI   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A send_server_response() 0 21 1
A make_sms_body() 0 11 2
A check_balance() 0 6 1
A send_sms() 0 7 1
A get_inbox() 0 6 1
1
<?php
2
3
namespace CynSMS;
4
5
class CynSMSAPI
6
{
7
8
    /**
9
     * @param $sms_body
10
     * @return string
11
     *
12
     * Make your sms information for post
13
     */
14
15
    private function make_sms_body($sms_body){
16
17
        $post_fields = '';
18
19
        foreach ($sms_body as $key => $value) {
20
            $post_fields .= urlencode($key) . '=' . $value . '&';
21
        }
22
23
        $post_fields=rtrim($post_fields,'&');
24
25
        return $post_fields;
26
    }
27
28
    /**
29
     * @param $url
30
     * @param $post_body
31
     * @return mixed
32
     *
33
     * Send request to server and get sms status
34
     *
35
     */
36
    private function send_server_response($url,$post_body){
37
38
        /**
39
         * Do not supply $post_fields directly as an argument to CURLOPT_POSTFIELDS,
40
         * despite what the PHP documentation suggests: cUrl will turn it into in a
41
         * multipart formpost, which is not supported:
42
         */
43
44
        $ch = curl_init( );
45
        curl_setopt ( $ch, CURLOPT_URL, $url );
46
        curl_setopt ( $ch, CURLOPT_POST, 1 );
47
        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
48
        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_body );
49
        // Allowing cUrl functions 20 second to execute
50
        curl_setopt ( $ch, CURLOPT_TIMEOUT, 20 );
51
        // Waiting 20 seconds while trying to connect
52
        curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, 20 );
53
        $response_string = curl_exec( $ch );
54
        curl_close( $ch );
55
56
        return $response_string;
57
58
    }
59
60
61
    /**
62
     * @param $sms_body
63
     * @param $url
64
     * @return mixed
65
     *
66
     * Send SMS Using API request
67
     */
68
69
    public function send_sms($sms_body, $url){
70
71
        $post_body='action=send-sms&'.$this->make_sms_body($sms_body,$url);
0 ignored issues
show
Unused Code introduced by
The call to CynSMS\CynSMSAPI::make_sms_body() has too many arguments starting with $url. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
        $post_body='action=send-sms&'.$this->/** @scrutinizer ignore-call */ make_sms_body($sms_body,$url);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
72
73
        $response=$this->send_server_response($url,$post_body);
74
75
        return $response;
76
77
    }
78
79
    /**
80
     * @param $api_key
81
     * @param $url
82
     * @return mixed
83
     *
84
     * Get All message for specific API Access
85
     *
86
     */
87
88
    public function get_inbox($api_key,$url){
89
        $post_body='action=get-inbox&api_key='.$api_key;
90
91
        $response=$this->send_server_response($url,$post_body);
92
93
        return $response;
94
95
96
    }
97
98
    /**
99
     * @param $api_key
100
     * @param $url
101
     * @return mixed
102
     *
103
     * Get Balance for specific user
104
     *
105
     */
106
107
    public function check_balance($api_key,$url){
108
        $post_body='action=check-balance&api_key='.$api_key;
109
110
        $response=$this->send_server_response($url,$post_body);
111
112
        return $response;
113
114
115
    }
116
117
118
}