GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Curl::getErrorMessage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Kobas\APIClient\Request;
4
5
/**
6
 * Class Curl
7
 *
8
 * @package Kobas\APIClient\Request
9
 */
10
class Curl implements HttpRequest
11
{
12
    /**
13
     * @var null|resource
14
     */
15
    private $handle = null;
16
17
    /**
18
     * @return $this
19
     */
20 3
    public function init()
21
    {
22 3
        if (is_null($this->handle)) {
23 3
            $this->handle = curl_init();
0 ignored issues
show
Documentation Bug introduced by
It seems like curl_init() can also be of type CurlHandle. However, the property $handle is declared as type null|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...
24 2
        }
25
26 3
        return $this;
27
    }
28
29
    /**
30
     * @param $url
31
     * @return Curl
32
     */
33 3
    public function setUrl($url)
34
    {
35 3
        return $this->setOption(CURLOPT_URL, $url);
36
    }
37
38
    /**
39
     * @param $name
40
     * @param $value
41
     * @return Curl
42
     */
43 3
    public function setOption($name, $value)
44
    {
45 3
        curl_setopt($this->handle, $name, $value);
46 3
        return $this;
47
    }
48
49
50
    /**
51
     * @return null|resource
52
     */
53 3
    public function getHandle()
54
    {
55 3
        return $this->handle;
56
    }
57
58
    /**
59
     * @return bool|string
60
     */
61
    public function execute()
62
    {
63
        return curl_exec($this->handle);
64
    }
65
66
    /**
67
     * @param $name
68
     * @return mixed
69
     */
70 3
    public function getInfo($name)
71
    {
72 3
        return curl_getinfo($this->handle, $name);
73
    }
74
75
    /**
76
     * @return array|false
77
     */
78
    public function getAllInfo()
79
    {
80
        return curl_getinfo($this->handle);
81
    }
82
83
    /**
84
     * @return int
85
     */
86
    public function getErrorNumber()
87
    {
88
        return curl_errno($this->handle);
89
    }
90
91
    /**
92
     * @return string
93
     */
94
    public function getErrorMessage()
95
    {
96
        return curl_error($this->handle);
97
    }
98
99
    /**
100
     * @return Curl
101
     */
102 3
    public function close()
103
    {
104 3
        curl_close($this->handle);
105 3
        $this->handle = null;
106
107 3
        return $this;
108
    }
109
}
110