Completed
Push — master ( 9814b8...5b35ba )
by Dmitry
02:52
created

Client::sendRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1.064

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
ccs 3
cts 5
cp 0.6
rs 9.6666
cc 1
eloc 5
nc 1
nop 1
crap 1.064
1
<?php
2
3
namespace Tarantool\Mapper;
4
5
use Tarantool\Connection\Connection;
6
use Tarantool\Client as OriginalClient;
7
use Tarantool\Request\Request;
8
9
class Client extends OriginalClient
10
{
11
    private $logging = true;
12
    private $log = [];
13
14 62
    public function connect()
15
    {
16 62
        $start = microtime(1);
17
18 62
        $result = parent::connect();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as parent::connect() (which targets Tarantool\Client::connect()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
19
        $this->log($start, Connection::class);
20
21
        return $result;
22
    }
23
24 62
    public function sendRequest(Request $request)
25
    {
26 62
        $start = microtime(1);
27 62
        $response = parent::sendRequest($request);
28
29
        $this->log($start, get_class($request), $request->getBody(), $response->getData());
0 ignored issues
show
Bug introduced by
It seems like $response->getData() targeting Tarantool\Response::getData() can also be of type null; however, Tarantool\Mapper\Client::log() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
30
31
        return $response;
32
    }
33
34
    private function log($start, $class, $request = [], $response = [])
35
    {
36
        if ($this->logging) {
37
            $this->log[] = new Event(microtime(1) - $start, $class, $request, $response);
38
        }
39
    }
40
41
    public function setLogging($logging)
42
    {
43
        $this->logging = $logging;
44
    }
45
46
    public function getLog()
47
    {
48
        return $this->log;
49
    }
50
}
51