HttpClientInterfaceProxy::sendRequest()   A
last analyzed

Complexity

Conditions 1
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
nc 2
nop 1
dl 0
loc 18
rs 9.9
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Collector;
6
7
use Psr\Http\Client\ClientInterface;
8
use Psr\Http\Message\RequestInterface;
9
use Psr\Http\Message\ResponseInterface;
10
11
final class HttpClientInterfaceProxy implements ClientInterface
12
{
13
    public function __construct(
14
        private readonly ClientInterface $decorated,
15
        private readonly HttpClientCollector $collector
16
    ) {
17
    }
18
19
    public function sendRequest(RequestInterface $request): ResponseInterface
20
    {
21
        /** @psalm-var array{file: string, line: int} $callStack */
22
        $callStack = debug_backtrace()[0];
23
24
        $uniqueId = random_bytes(36);
25
        $startTime = microtime(true);
26
        $this->collector->collect($request, $startTime, $callStack['file'] . ':' . $callStack['line'], $uniqueId);
0 ignored issues
show
Bug introduced by
It seems like $startTime can also be of type string; however, parameter $startTime of Yiisoft\Yii\Debug\Collec...entCollector::collect() does only seem to accept double, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
        $this->collector->collect($request, /** @scrutinizer ignore-type */ $startTime, $callStack['file'] . ':' . $callStack['line'], $uniqueId);
Loading history...
27
28
        $response = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $response is dead and can be removed.
Loading history...
29
        try {
30
            $response = $this->decorated->sendRequest($request);
31
        } finally {
32
            $endTime = microtime(true);
33
            $this->collector->collectTotalTime($response, $endTime, $uniqueId);
0 ignored issues
show
Bug introduced by
It seems like $endTime can also be of type string; however, parameter $endTime of Yiisoft\Yii\Debug\Collec...tor::collectTotalTime() does only seem to accept double, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
            $this->collector->collectTotalTime($response, /** @scrutinizer ignore-type */ $endTime, $uniqueId);
Loading history...
34
        }
35
36
        return $response;
37
    }
38
}
39