Completed
Push — master ( b0f180...eae8a5 )
by Dmitry
03:43
created

Client   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 1
cbo 4
dl 0
loc 42
ccs 19
cts 19
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A connect() 0 9 1
A sendRequest() 0 9 1
A log() 0 6 2
A getLog() 0 4 1
A setLogging() 0 4 1
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 60
    public function connect()
15
    {
16 60
        $start = microtime(1);
17
18 60
        $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 60
        $this->log($start, Connection::class);
20
21 60
        return $result;
22
    }
23
24 60
    public function sendRequest(Request $request)
25
    {
26 60
        $start = microtime(1);
27 60
        $response = parent::sendRequest($request);
28
29 60
        $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 60
        return $response;
32
    }
33
34 60
    private function log($start, $class, $request = [], $response = [])
35
    {
36 60
        if ($this->logging) {
37 60
            $this->log[] = new Event(microtime(1) - $start, $class, $request, $response);
38
        }
39 60
    }
40
41 1
    public function setLogging($logging)
42
    {
43 1
        $this->logging = $logging;
44 1
    }
45
46 2
    public function getLog()
47
    {
48 2
        return $this->log;
49
    }
50
}
51