TransportLoggingDecorator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 2
eloc 13
c 2
b 1
f 1
dl 0
loc 29
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 17 1
A __construct() 0 4 1
1
<?php
2
/*
3
 * This file is part of JSON RPC Client.
4
 *
5
 * (c) Igor Lazarev <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Strider2038\JsonRpcClient\Transport;
12
13
use Psr\Log\LoggerInterface;
14
15
/**
16
 * @internal
17
 *
18
 * @author Igor Lazarev <[email protected]>
19
 */
20
class TransportLoggingDecorator implements TransportInterface
21
{
22
    private TransportInterface $decorated;
23
24
    private LoggerInterface $logger;
25
26
    public function __construct(TransportInterface $decorated, LoggerInterface $logger)
27
    {
28 8
        $this->decorated = $decorated;
29
        $this->logger = $logger;
30 8
    }
31 8
32 8
    public function send(string $request): string
33
    {
34 6
        $this->logger->debug('Sending JSON RPC request.', ['body' => $request]);
35
36 6
        $sentAt = microtime(true);
37
38 6
        $response = $this->decorated->send($request);
39
40 6
        $this->logger->debug(
41
            'JSON RPC response received.',
42 5
            [
43 5
                'body'     => $response,
44
                'duration' => microtime(true) - $sentAt,
45 5
            ]
46 5
        );
47
48
        return $response;
49
    }
50
}
51