Curl   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 19 4
A getResponse() 0 8 2
1
<?php
2
3
namespace Faulancer\Http\Adapter;
4
5
use Faulancer\Exception\ClientException;
6
use Faulancer\Http\Request;
7
8
/**
9
 * Class Curl
10
 * @package Faulancer\Http\Adapter
11
 * @author  Florian Knapp <[email protected]>
12
 */
13
class Curl extends AbstractAdapter
14
{
15
    /**
16
     * @param Request $request
17
     * @return void
18
     */
19
    public function send(Request $request)
20
    {
21
        $ch = curl_init($request->getUri());
22
23
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
24
25
        if (!empty($request->getHeaders())) {
26
            curl_setopt($ch, CURLOPT_HTTPHEADER, $request->getHeaders());
27
        }
28
29
        if ($request->getMethod() === 'POST' && !empty($request->getBody())) {
30
            curl_setopt($ch, CURLOPT_POSTFIELDS, $request->getBody());
31
        }
32
33
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0');
34
35
        $this->response = curl_exec($ch);
36
        curl_close($ch);
37
    }
38
39
    /**
40
     * @return mixed
41
     * @throws ClientException
42
     */
43
    public function getResponse()
44
    {
45
        if (empty($this->response)) {
46
            throw new ClientException('You have to call the \'send\' method first.');
47
        }
48
49
        return $this->response;
50
    }
51
52
}