Completed
Push — master ( 6398a1...d95ab0 )
by Sergey
03:32
created

CurlAdapter::hasErrors()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 0
1
<?php
2
3
namespace seregazhuk\PinterestBot\Api;
4
5
use seregazhuk\PinterestBot\Contracts\HttpInterface;
6
7
/**
8
 * Class CurlAdapter
9
 *
10
 * @package seregazhuk\PinterestBot
11
 * @property string $cookieJar
12
 * @property string $cookePath
13
 */
14
class CurlAdapter implements HttpInterface
15
{
16
17
    protected $http;
18
    protected $options;
19
    protected $loggedIn;
20
21
    public $cookieJar;
22
    public $cookiePath;
23
24
    /**
25
     * Contains the curl instance
26
     *
27
     * @var resource
28
     */
29
    private $curl;
30
31
    /**
32
     * Initializes curl resource
33
     *
34
     * @access public
35
     * @param string $url
36
     */
37
    public function init($url)
38
    {
39
        $this->curl = curl_init($url);
40
    }
41
42
    /**
43
     * Sets an option in the curl instance
44
     *
45
     * @access public
46
     * @param  string $option
47
     * @param  string $value
48
     * @return $this
49
     */
50
    public function setOption($option, $value)
51
    {
52
        curl_setopt($this->curl, $option, $value);
53
54
        return $this;
55
    }
56
57
    /**
58
     * Sets multiple options at the same time
59
     *
60
     * @access public
61
     * @param  array $options
62
     * @return $this
63
     */
64
    public function setOptions(array $options = [])
65
    {
66
        curl_setopt_array($this->curl, $options);
67
68
        return $this;
69
    }
70
71
72
    /**
73
     * Check if the curl request ended up with errors
74
     *
75
     * @access public
76
     * @return boolean
77
     */
78
    public function hasErrors()
79
    {
80
        return curl_errno($this->curl) ? true : false;
81
    }
82
83
    /**
84
     * Get curl errors
85
     *
86
     * @access public
87
     * @return string
88
     */
89
    public function getErrors()
90
    {
91
        return curl_error($this->curl);
92
    }
93
94
    /**
95
     * Get curl info key
96
     *
97
     * @access public
98
     * @param  string $key
99
     * @return string
100
     */
101
    public function getInfo($key)
102
    {
103
        return curl_getinfo($this->curl, $key);
104
    }
105
106
    /**
107
     * Close the curl resource
108
     *
109
     * @access public
110
     * @return void
111
     */
112
    public function close()
113
    {
114
        curl_close($this->curl);
115
    }
116
117
118
    /**
119
     * Executes curl request
120
     *
121
     * @return array
122
     */
123
    public function execute()
124
    {
125
        return curl_exec($this->curl);
126
    }
127
}
128