Completed
Push — master ( b6e12f...e73452 )
by Janusz
14:44 queued 07:31
created

CurlClient   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 20
dl 0
loc 49
c 0
b 0
f 0
ccs 20
cts 20
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fixHeaders() 0 10 2
A request() 0 33 2
1
<?php
2
3
namespace Nixilla\Api\LoggerBundle\Proxy\Twilio;
4
5
use Nixilla\Api\LoggerBundle\Traits\Log;
6
use Twilio\Http\CurlClient as BaseClient;
7
use Twilio\Http\Response;
8
9
class CurlClient extends BaseClient
10
{
11
    use Log;
12
13 1
    public function request(
14
        $method,
15
        $url,
16
        $params = [],
17
        $data = [],
18
        $headers = [],
19
        $user = null,
20
        $password = null,
21
        $timeout = null
22
    )
23
    {
24 1
        $start = microtime(true);
25
26
        /** @var Response $result */
27 1
        $result = parent::request($method, $url, $params, $data, $headers, $user, $password, $timeout);
28
29 1
        if($this->hasLogger())
30
        {
31 1
            $time = microtime(true) - $start;
32
33 1
            $this->getLogger()->logCall(
34 1
                $url,
35 1
                '',
36 1
                $method,
37 1
                $time,
38 1
                $this->fixHeaders($headers),
39 1
                $data,
40 1
                $result->getHeaders(),
41 1
                json_encode($result->getContent())
42
            );
43
        }
44
45 1
        return $result;
46
    }
47
48 1
    private function fixHeaders($headers)
49
    {
50 1
        $fixed = [];
51
52 1
        foreach ($headers as $name => $value)
53
        {
54 1
            $fixed[] = sprintf('%s: %s', $name, $value);
55
        }
56
57 1
        return $fixed;
58
    }
59
}
60