Completed
Push — master ( adb3c9...6fd31a )
by Vadim
02:31
created

CurlRequest::getInfo()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2.0625
1
<?php
2
3
namespace AudioManager\Request;
4
5
/**
6
 * Class CurlRequest
7
 * @package AudioManager\Request
8
 */
9
class CurlRequest implements RequestInterface
10
{
11
    /**
12
     * Curl handle
13
     * @var resource
14
     */
15
    private $handle;
16
17
    /**
18
     * Constructor
19
     * Create curl handle
20
     * @param $url
21
     */
22 13
    public function __construct($url = null)
23
    {
24 13
        $this->handle = curl_init($url);
25 13
    }
26
27
    /**
28
     * Close connection
29
     */
30 3
    public function __destruct()
31
    {
32 3
        $this->close();
33 3
    }
34
35
    /**
36
     * @param $url
37
     * @return bool
38
     */
39 3
    public function setUrl($url)
40
    {
41 3
        return $this->setOption(CURLOPT_URL, $url);
42
    }
43
    
44
    /**
45
     * Set option
46
     * @param string $name
47
     * @param mixed $value
48
     * @return $this
49
     */
50 3
    public function setOption($name, $value)
51
    {
52 3
        curl_setopt($this->handle, $name, $value);
53 3
        return $this;
54
    }
55
56
    /**
57
     * Execute request
58
     * @return mixed
59
     */
60
    public function execute()
61
    {
62
        return curl_exec($this->handle);
63
    }
64
65
    /**
66
     * Get info from request
67
     * @param int $opt
68
     * @return mixed
69
     */
70 2
    public function getInfo($opt = null)
71
    {
72 2
        if ($opt !== null) {
73
            return curl_getinfo($this->handle, $opt);
74
        }
75 2
        return curl_getinfo($this->handle);
76
    }
77
78
    /**
79
     * Get error message
80
     * @return mixed
81
     */
82
    public function getError()
83
    {
84
        return curl_error($this->handle);
85
    }
86
87
    /**
88
     * Close http connection
89
     * @return void
90
     */
91 3
    public function close()
92
    {
93 3
        curl_close($this->handle);
94 3
    }
95
}
96