Http::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Ip2c\Http;
4
5
use Ip2c\Curl\LibCurl;
6
7
class Http
8
{
9
    /** @var LibCurl */
10
    private $libCurl;
11
12
    /**
13
     * Http constructor.
14
     * @param LibCurl $libCurl
15
     */
16 5
    public function __construct(LibCurl $libCurl)
17
    {
18 5
        $this->libCurl = $libCurl;
19 5
    }
20
21
    /**
22
     * @param $url
23
     * @return string
24
     * @throws \Exception
25
     */
26 3
    public function request($url)
27
    {
28 3
        $ch = $this->libCurl->init();
29 3
        $this->libCurl->setOpt($ch, CURLOPT_SSL_VERIFYPEER, 0);
30 3
        $this->libCurl->setOpt($ch, CURLOPT_URL, $url);
31 3
        $this->libCurl->setOpt($ch, CURLOPT_RETURNTRANSFER, 1);
32 3
        $this->libCurl->setOpt($ch, CURLOPT_TIMEOUT, 10);
33
34 3
        $data = $this->libCurl->exec($ch);
35
36 3
        if ($this->libCurl->errno($ch)) {
37 1
            throw new \Exception($this->libCurl->error($ch), $this->libCurl->errno($ch));
38
        } else {
39 2
            $this->libCurl->close($ch);
40 2
            return $data;
41
        }
42
    }
43
}
44