Completed
Pull Request — develop (#273)
by Samuel
19:01 queued 08:39
created

GuzzleAdapter::send()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 10
ccs 0
cts 9
cp 0
rs 9.4286
c 2
b 0
f 1
cc 2
eloc 6
nc 2
nop 1
crap 6
1
<?php
2
/**
3
 * Guzzle adapter class
4
 */
5
6
namespace Graviton\ProxyBundle\Adapter\Guzzle;
7
8
use GuzzleHttp\Client;
9
use Proxy\Adapter\AdapterInterface;
10
use Psr\Http\Message\RequestInterface;
11
use Psr\Http\Message\ResponseInterface;
12
13
/**
14
 *
15
 *
16
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
17
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
18
 * @link     http://swisscom.ch
19
 */
20
class GuzzleAdapter implements AdapterInterface
21
{
22
    /**
23
     * Guzzle client
24
     *
25
     * @var Client
26
     */
27
    private $client;
28
29
    /**
30
     * curl options
31
     *
32
     * @var array
33
     */
34
    private $curlOptions;
35
    /**
36
     * constructor
37
     *
38
     * @param Client $client guzzle client
39
     */
40
    public function __construct(Client $client)
41
    {
42
        $this->client = $client;
43
    }
44
45
    /**
46
     * @inheritDoc
47
     *
48
     * @param RequestInterface $request request
49
     *
50
     * @return ResponseInterface
51
     */
52
    public function send(RequestInterface $request)
53
    {
54
        $options = array('curl' => []);
55
        foreach ($this->curlOptions as $option => $value) {
56
            $options['curl'][constant('CURLOPT_'.strtoupper($option))] = $value;
57
        }
58
        $options['verify'] = __DIR__.'/../../Resources/cert/cacert.pem';
59
60
        return $this->client->send($request, $options);
61
    }
62
63
    /**
64
     * set curl options
65
     *
66
     * @param array $curlOptions the curl options
67
     *
68
     * @return void
69
     */
70
    public function setCurlOptions(array $curlOptions)
71
    {
72
        $this->curlOptions = $curlOptions;
73
    }
74
}
75