Completed
Push — master ( eaf181...b6e12f )
by Janusz
16:44 queued 11:21
created

CurlClient::request()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 33
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 0
cts 15
cp 0
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 14
nc 2
nop 8
crap 6

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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
    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
        $start = microtime(true);
25
26
        /** @var Response $result */
27
        $result = parent::request($method, $url, $params, $data, $headers, $user, $password, $timeout);
28
29
        if($this->hasLogger())
30
        {
31
            $time = microtime(true) - $start;
32
33
            $this->getLogger()->logCall(
34
                $url,
35
                '',
36
                $method,
37
                $time,
38
                $this->fixHeaders($headers),
39
                $data,
40
                $result->getHeaders(),
41
                json_encode($result->getContent())
42
            );
43
        }
44
45
        return $result;
46
    }
47
48
    private function fixHeaders($headers)
49
    {
50
        $fixed = [];
51
52
        foreach ($headers as $name => $value)
53
        {
54
            $fixed[] = sprintf('%s: %s', $name, $value);
55
        }
56
57
        return $fixed;
58
    }
59
}
60