CurlWrapper::getInfo()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace GloBee\PaymentApi\Connectors;
4
5
use GloBee\PaymentApi\Exceptions\Connectors\CurlConnectionException;
6
7
/**
8
 * @codeCoverageIgnore
9
 */
10
class CurlWrapper
11
{
12
    /**
13
     * Curl Resource
14
     *
15
     * @var resource
16
     */
17
    protected $client;
18
19
    /**
20
     * @return resource Curl Resource
21
     */
22
    protected function getClient()
23
    {
24
        if (!is_resource($this->client)) {
25
            $this->client = curl_init();
0 ignored issues
show
Documentation Bug introduced by
It seems like curl_init() can also be of type false. However, the property $client 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
        return $this->client;
29
    }
30
31
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$key" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$value" missing
Loading history...
32
     * @param $key
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
33
     * @param $value
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
34
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
35
    public function setOption($key, $value)
0 ignored issues
show
Coding Style introduced by
Type hint "key" missing for
Loading history...
Coding Style introduced by
Type hint "value" missing for
Loading history...
36
    {
37
        curl_setopt($this->getClient(), $key, $value);
38
    }
39
40
    /**
41
     * @param array $options
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
42
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
43
    public function setOptions(array $options)
44
    {
45
        curl_setopt_array($this->getClient(), $options);
46
    }
47
48
    /**
49
     * @return mixed
50
     *
51
     * @throws \GloBee\PaymentApi\Exceptions\Connectors\CurlConnectionException
0 ignored issues
show
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
52
     */
53
    public function exec()
54
    {
55
        $result = curl_exec($this->getClient());
56
        if ($result === false) {
57
            throw new CurlConnectionException($this);
58
        }
59
60
        return $result;
61
    }
62
63
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$type" missing
Loading history...
64
     * @param $type
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
65
     *
66
     * @return mixed
67
     */
68
    public function getInfo($type)
0 ignored issues
show
Coding Style introduced by
Type hint "type" missing for
Loading history...
69
    {
70
        return curl_getinfo($this->getClient(), $type);
71
    }
72
73
    /**
74
     * Returns the cUrl error string
75
     *
76
     * @return string
77
     */
78
    public function getErrorMessage()
79
    {
80
        return curl_error($this->getClient());
81
    }
82
83
    /**
84
     * Returns the cUrl error number
85
     *
86
     * @return int
0 ignored issues
show
Coding Style introduced by
Expected "integer" but found "int" for function return type
Loading history...
87
     */
88
    public function getErrorNo()
89
    {
90
        return curl_errno($this->getClient());
91
    }
92
93
    /**
94
     * Close the cUrl resource
95
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
96
    public function close()
97
    {
98
        curl_close($this->client);
99
    }
100
}
101