Issues (65)

src/Browser/HttpBrowser.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Zenstruck\Browser;
4
5
use Symfony\Component\BrowserKit\HttpBrowser as SymfonyHttpBrowser;
6
use Symfony\Component\HttpKernel\Profiler\Profile;
7
use Symfony\Component\HttpKernel\Profiler\Profiler;
8
9
/**
10
 * @author Kevin Bond <[email protected]>
11
 *
12
 * @extends BrowserKitBrowser<SymfonyHttpBrowser>
13
 */
14
class HttpBrowser extends BrowserKitBrowser
15
{
16
    private ?Profiler $profiler = null;
17
18
    final public function __construct(SymfonyHttpBrowser $inner)
19
    {
20
        parent::__construct($inner);
21
    }
22
23
    final public function setProfiler(Profiler $profiler): self
24
    {
25
        $this->profiler = $profiler;
26
27
        return $this;
28
    }
29
30
    /**
31
     * Profile collection must be enabled globally for this feature.
32
     */
33
    final public function profile(): Profile
34
    {
35
        if (!$this->profiler) {
36
            throw new \RuntimeException('The profiler has not been set. Is profiling enabled?');
37
        }
38
39
        if (!$token = $this->inner()->getInternalResponse()->getHeader('x-debug-token')) {
40
            throw new \RuntimeException('Profiling is not enabled for this request. You must enable profile collection globally when using the HttpBrowser.');
41
        }
42
43
        if (!$profile = $this->profiler->loadProfile($token)) {
0 ignored issues
show
It seems like $token can also be of type array; however, parameter $token of Symfony\Component\HttpKe...Profiler::loadProfile() does only seem to accept string, 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

43
        if (!$profile = $this->profiler->loadProfile(/** @scrutinizer ignore-type */ $token)) {
Loading history...
44
            throw new \RuntimeException('Could not find profile for this request.');
45
        }
46
47
        return $profile;
48
    }
49
}
50