Issues (158)

src/Collector/HttpClientInterfaceProxy.php (3 issues)

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(private ClientInterface $decorated, private HttpClientCollector $collector)
14
    {
15
    }
16
17
    public function sendRequest(RequestInterface $request): ResponseInterface
18
    {
19
        /** @psalm-var array{file: string, line: int} $callStack */
20
        $callStack = debug_backtrace()[0];
21
22
        $uniqueId = random_bytes(36);
23
        $startTime = microtime(true);
24
        $this->collector->collect($request, $startTime, $callStack['file'] . ':' . $callStack['line'], $uniqueId);
0 ignored issues
show
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

24
        $this->collector->collect($request, /** @scrutinizer ignore-type */ $startTime, $callStack['file'] . ':' . $callStack['line'], $uniqueId);
Loading history...
25
26
        $response = null;
0 ignored issues
show
The assignment to $response is dead and can be removed.
Loading history...
27
        try {
28
            $response = $this->decorated->sendRequest($request);
29
        } finally {
30
            $endTime = microtime(true);
31
            $this->collector->collectTotalTime($response, $endTime, $uniqueId);
0 ignored issues
show
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

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