TransportLoggingDecorator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 2
c 1
b 0
f 1
dl 0
loc 4
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 2
crap 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