CurlClient::getResponse()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 10
cts 10
cp 1
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
namespace mikemix\Wiziq\Http;
3
4
use mikemix\Wiziq\Common\Http\ClientInterface;
5
use mikemix\Wiziq\Common\Http\Exception;
6
7
class CurlClient implements ClientInterface
8
{
9
    /**
10
     * {@inheritdoc}
11
     */
12 2
    public function getResponse($url, array $data)
13
    {
14 2
        $ch = curl_init($url);
15 2
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
16 2
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
17
18 2
        $response = curl_exec($ch);
19 2
        $error    = curl_error($ch);
20 2
        curl_close($ch);
21
22 2
        if (!$response) {
23 1
            throw Exception\InvalidResponseException::with($url, $error);
24
        }
25
26 1
        return $response;
27
    }
28
}
29