InstagramCurl::errno()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Maztech\HttpClients;
4
5
/**
6
 * Class InstagramCurl
7
 *
8
 * Abstraction for the procedural curl elements so that curl can be mocked and the implementation can be tested.
9
 *
10
 * @package Instagram
11
 */
12
class InstagramCurl
13
{
14
15
    /**
16
     * @var resource Curl resource instance
17
     */
18
    protected $curl;
19
20
    /**
21
     * Make a new curl reference instance
22
     */
23
    public function init()
24
    {
25
        $this->curl = curl_init();
0 ignored issues
show
Documentation Bug introduced by
It seems like curl_init() can also be of type CurlHandle. However, the property $curl is declared as type resource. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
26
    }
27
28
    /**
29
     * Set a curl option
30
     *
31
     * @param $key
32
     * @param $value
33
     */
34
    public function setopt($key, $value)
35
    {
36
        curl_setopt($this->curl, $key, $value);
37
    }
38
39
    /**
40
     * Set an array of options to a curl resource
41
     *
42
     * @param array $options
43
     */
44
    public function setoptArray(array $options)
45
    {
46
        curl_setopt_array($this->curl, $options);
47
    }
48
49
    /**
50
     * Send a curl request
51
     *
52
     * @return mixed
53
     */
54
    public function exec()
55
    {
56
        return curl_exec($this->curl);
57
    }
58
59
    /**
60
     * Return the curl error number
61
     *
62
     * @return int
63
     */
64
    public function errno()
65
    {
66
        return curl_errno($this->curl);
67
    }
68
69
    /**
70
     * Return the curl error message
71
     *
72
     * @return string
73
     */
74
    public function error()
75
    {
76
        return curl_error($this->curl);
77
    }
78
79
    /**
80
     * Get info from a curl reference
81
     *
82
     * @param $type
83
     *
84
     * @return mixed
85
     */
86
    public function getinfo($type)
87
    {
88
        return curl_getinfo($this->curl, $type);
89
    }
90
91
    /**
92
     * Get the currently installed curl version
93
     *
94
     * @return array
95
     */
96
    public function version()
97
    {
98
        return curl_version();
99
    }
100
101
    /**
102
     * Close the resource connection to curl
103
     */
104
    public function close()
105
    {
106
        curl_close($this->curl);
107
    }
108
}
109