Code Duplication    Length = 28-29 lines in 2 locations

src/ridvanbaluyos/sms/providers/Nexmo.php 1 location

@@ 72-100 (lines=29) @@
69
     * This function gets the account balance.
70
     *
71
     */
72
    public function balance()
73
    {
74
        try {
75
            $conf = Config::load(__DIR__ . '/../config/providers.json')[$this->className];
76
77
            $query = array(
78
                'api_key' => $conf['api_key'],
79
                'api_secret' => $conf['api_secret']
80
            );
81
82
            $query = http_build_query($query);
83
84
            $ch = curl_init();
85
            curl_setopt($ch, CURLOPT_URL, $conf['url'] . '/account/get-balance?' . $query);
86
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
87
            $result = curl_exec($ch);
88
            curl_close($ch);
89
90
            $result = json_decode($result);
91
92
            if (is_float($result->value) || is_integer($result->value)) {
93
                return $this->response(200, $result, null, $this->className);
94
            } else {
95
                return $this->response(500, $result, null, $this->className);
96
            }
97
        } catch (Exception $e) {
98
99
        }
100
    }
101
}
102

src/ridvanbaluyos/sms/providers/Semaphore.php 1 location

@@ 71-98 (lines=28) @@
68
     * This function gets the account balance.
69
     *
70
     */
71
    public function balance()
72
    {
73
        try {
74
            $conf = Config::load(__DIR__ . '/../config/providers.json')[$this->className];
75
            $query = [
76
                'api' => $conf['api'],
77
            ];
78
79
            $url = $conf['url'] . '/account?' . http_build_query($query);
80
81
            $ch = curl_init();
82
            curl_setopt($ch,CURLOPT_URL,$url);
83
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
84
            curl_setopt($ch, CURLOPT_TIMEOUT, 240);
85
            $result = curl_exec($ch);
86
            curl_close($ch);
87
88
            $result = json_decode($result);
89
90
            if ($result->status === 'success') {
91
                return $this->response(200, $result, null, $this->className);
92
            } else {
93
                return $this->response(500, $result->message, null, $this->className);
94
            }
95
        } catch (Exception $e) {
96
97
        }
98
    }
99
}