Http   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 37
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A request() 0 17 2
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