Passed
Push — 1.x ( 5a4286...a604cc )
by Kevin
01:41
created

KernelBrowser::profile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace Zenstruck\Browser;
4
5
use Symfony\Bundle\FrameworkBundle\KernelBrowser as SymfonyKernelBrowser;
6
use Symfony\Component\HttpKernel\Profiler\Profile;
7
8
/**
9
 * @author Kevin Bond <[email protected]>
10
 *
11
 * @method SymfonyKernelBrowser inner()
12
 */
13
class KernelBrowser extends BrowserKitBrowser implements ProfileAware
14
{
15
    final public function __construct(SymfonyKernelBrowser $inner)
16
    {
17
        parent::__construct($inner);
18
    }
19
20
    /**
21
     * By default, exceptions made during a request are caught and converted
22
     * to responses by Symfony. This disables this behaviour and actually
23
     * throws the exception.
24
     *
25
     * @return static
26
     */
27
    final public function throwExceptions(): self
28
    {
29
        $this->inner()->catchExceptions(false);
30
31
        return $this;
32
    }
33
34
    /**
35
     * Re-enables catching exceptions.
36
     *
37
     * @return static
38
     */
39
    final public function catchExceptions(): self
40
    {
41
        $this->inner()->catchExceptions(true);
42
43
        return $this;
44
    }
45
46
    /**
47
     * Enable profiling for the next request. Not required if profiling is
48
     * globally enabled.
49
     *
50
     * @return static
51
     */
52
    final public function withProfiling(): self
53
    {
54
        $this->inner()->enableProfiler();
55
56
        return $this;
57
    }
58
59
    final public function profile(): Profile
60
    {
61
        if (!$profile = $this->inner()->getProfile()) {
62
            throw new \RuntimeException('Profiler not enabled for this request. Try calling ->withProfiling() before the request.');
63
        }
64
65
        return $profile;
66
    }
67
}
68