CurlHttpClient   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 51
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 13 1
A exists() 0 16 1
1
<?php
2
3
namespace MediaMonks\SonataMediaBundle\Client;
4
5
use Symfony\Component\HttpFoundation\Response;
6
7
class CurlHttpClient implements HttpClientInterface
8
{
9
    /**
10
     * @var int
11
     */
12
    private $connectTimeout = 5;
13
14
    /**
15
     * @var int
16
     */
17
    private $timeout = 5;
18
19
    /**
20
     * @param string $url
21
     * @return string
22
     */
23 4
    public function getData($url)
24
    {
25 4
        $ch = curl_init();
26
27 4
        curl_setopt($ch, CURLOPT_HEADER, 0);
28 4
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
29 4
        curl_setopt($ch, CURLOPT_URL, $url);
30
31 4
        $data = curl_exec($ch);
32 4
        curl_close($ch);
33
34 4
        return $data;
35
    }
36
37
    /**
38
     * @param string $url
39
     * @return bool
40
     */
41 1
    public function exists($url)
42
    {
43 1
        $ch = curl_init();
44 1
        curl_setopt($ch, CURLOPT_URL, $url);
45 1
        curl_setopt($ch, CURLOPT_NOBODY, true);
46 1
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
47 1
        curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
48 1
        curl_setopt($ch, CURLOPT_HEADER, false);
49 1
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
50
51 1
        curl_exec($ch);
52 1
        $info = curl_getinfo($ch);
53 1
        curl_close($ch);
54
55 1
        return $info['http_code'] === Response::HTTP_OK;
56
    }
57
}
58