Passed
Push — master ( 230365...2345ea )
by Max Alex
01:50
created

Connection::post()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 14
nc 1
nop 2
dl 0
loc 23
rs 9.7998
c 0
b 0
f 0
1
<?php
2
3
namespace CodePhix\Asaas;
4
5
class Connection {
6
    
7
    public $http;
8
    public $api_key;
9
    public $api_key_live;
10
    public $api_status;
11
    public $base_url;
12
    public $headers;
13
14
    public function __construct() {
15
        $this->api_key = PAYMENT['asaas']['chave'];
0 ignored issues
show
Bug introduced by
The constant CodePhix\Asaas\PAYMENT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
16
        $this->api_key_live = PAYMENT['asaas']['chavelivre'];
17
        $this->api_status = PAYMENT['asaas']['status'];
18
        $this->base_url = "https://" . ((PAYMENT['asaas']['status']) ? 'sandbox' : 'www');
19
        return $this;
20
    }
21
22
23
    public function get($url, $option = false, $custom = false )
24
    {
25
26
        $ch = curl_init();
27
        curl_setopt($ch, CURLOPT_URL, $this->base_url .'.asaas.com/api/v3'. $url."?".$option);
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_setopt() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

27
        curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_URL, $this->base_url .'.asaas.com/api/v3'. $url."?".$option);
Loading history...
28
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
29
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
30
31
        if(!empty($custom)){
32
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $custom);
33
        }
34
35
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
36
            "Content-Type: application/json",
37
            "access_token: ".(($this->api_status == 1) ? $this->api_key_live : $this->api_key)
38
        ));
39
40
        $response = curl_exec($ch);
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_exec() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

40
        $response = curl_exec(/** @scrutinizer ignore-type */ $ch);
Loading history...
41
        curl_close($ch);
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_close() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

41
        curl_close(/** @scrutinizer ignore-type */ $ch);
Loading history...
42
        $response = json_decode($response);
43
44
        //$response = $this->http->request('GET', $this->base_url . $url);
45
46
        return $response;
47
    }
48
    
49
    public function post($url, $params)
50
    {
51
        $params = json_encode($params);
52
        $ch = curl_init();
53
54
        curl_setopt($ch, CURLOPT_URL, $this->base_url .'.asaas.com/api/v3'. $url);
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_setopt() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

54
        curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_URL, $this->base_url .'.asaas.com/api/v3'. $url);
Loading history...
55
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
56
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
57
58
        curl_setopt($ch, CURLOPT_POST, TRUE);
59
60
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
61
62
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
63
            "Content-Type: application/json",
64
            "access_token: ".(($this->api_status == 1) ? $this->api_key_live : $this->api_key)
65
        ));
66
67
        $response = curl_exec($ch);
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_exec() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

67
        $response = curl_exec(/** @scrutinizer ignore-type */ $ch);
Loading history...
68
        curl_close($ch);
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_close() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

68
        curl_close(/** @scrutinizer ignore-type */ $ch);
Loading history...
69
        $response = json_decode($response);
70
71
        return $response;
72
73
    }
74
    
75
}