CurlRequest::setUrl()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.1481

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 6
cp 0.6667
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2.1481
1
<?php
2
3
namespace Zenapply\Request;
4
5
class CurlRequest implements HttpRequest
6
{
7
    private $handle = null;
8
9 3
    public function __construct($url) {
10 3
        $this->setUrl($url);
11 3
    }
12
13 3
    public function setUrl($url) {
14 3
        if($this->handle !== null){
15
            $this->close();
16
        }
17 3
        $this->handle = curl_init($url);
18 3
    }
19
20
    public function setOptionArray($array) {
21
        foreach ($array as $key => $value) {
22
            $this->setOption($key,$value);
23
        }
24
    }
25
26
    public function setOption($name, $value) {
27
        curl_setopt($this->handle, $name, $value);
28
    }
29
30
    public function execute() {
31
        return curl_exec($this->handle);
32
    }
33
34
    public function getInfo($name) {
35
        return curl_getinfo($this->handle, $name);
36
    }
37
38
    public function close() {
39
        curl_close($this->handle);
40
    }
41
}