KernelBrowser   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 9
eloc 17
c 4
b 0
f 1
dl 0
loc 84
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A catchExceptions() 0 5 1
A throwExceptions() 0 5 1
A disableReboot() 0 5 1
A withProfiling() 0 5 1
A enableReboot() 0 5 1
A actingAs() 0 5 1
A profile() 0 7 2
1
<?php
2
3
namespace Zenstruck\Browser;
4
5
use Symfony\Bundle\FrameworkBundle\KernelBrowser as SymfonyKernelBrowser;
6
use Symfony\Component\HttpKernel\Profiler\Profile;
7
use Symfony\Component\Security\Core\User\UserInterface;
8
9
/**
10
 * @author Kevin Bond <[email protected]>
11
 *
12
 * @extends BrowserKitBrowser<SymfonyKernelBrowser>
13
 */
14
class KernelBrowser extends BrowserKitBrowser
15
{
16
    final public function __construct(SymfonyKernelBrowser $inner)
17
    {
18
        parent::__construct($inner);
19
    }
20
21
    /**
22
     * @see SymfonyKernelBrowser::disableReboot()
23
     *
24
     * @return static
25
     */
26
    final public function disableReboot(): self
27
    {
28
        $this->inner()->disableReboot();
0 ignored issues
show
Bug introduced by
The method disableReboot() does not exist on Symfony\Component\BrowserKit\AbstractBrowser. It seems like you code against a sub-type of Symfony\Component\BrowserKit\AbstractBrowser such as Symfony\Bundle\FrameworkBundle\KernelBrowser. ( Ignorable by Annotation )

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

28
        $this->inner()->/** @scrutinizer ignore-call */ disableReboot();
Loading history...
29
30
        return $this;
31
    }
32
33
    /**
34
     * @see SymfonyKernelBrowser::enableReboot()
35
     *
36
     * @return static
37
     */
38
    final public function enableReboot(): self
39
    {
40
        $this->inner()->enableReboot();
0 ignored issues
show
Bug introduced by
The method enableReboot() does not exist on Symfony\Component\BrowserKit\AbstractBrowser. It seems like you code against a sub-type of Symfony\Component\BrowserKit\AbstractBrowser such as Symfony\Bundle\FrameworkBundle\KernelBrowser. ( Ignorable by Annotation )

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

40
        $this->inner()->/** @scrutinizer ignore-call */ enableReboot();
Loading history...
41
42
        return $this;
43
    }
44
45
    /**
46
     * By default, exceptions made during a request are caught and converted
47
     * to responses by Symfony. This disables this behaviour and actually
48
     * throws the exception.
49
     *
50
     * @return static
51
     */
52
    final public function throwExceptions(): self
53
    {
54
        $this->inner()->catchExceptions(false);
0 ignored issues
show
Bug introduced by
The method catchExceptions() does not exist on Symfony\Component\BrowserKit\AbstractBrowser. It seems like you code against a sub-type of Symfony\Component\BrowserKit\AbstractBrowser such as Symfony\Component\HttpKernel\HttpKernelBrowser. ( Ignorable by Annotation )

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

54
        $this->inner()->/** @scrutinizer ignore-call */ catchExceptions(false);
Loading history...
55
56
        return $this;
57
    }
58
59
    /**
60
     * Re-enables catching exceptions.
61
     *
62
     * @return static
63
     */
64
    final public function catchExceptions(): self
65
    {
66
        $this->inner()->catchExceptions(true);
67
68
        return $this;
69
    }
70
71
    /**
72
     * Enable profiling for the next request. Not required if profiling is
73
     * globally enabled.
74
     *
75
     * @return static
76
     */
77
    final public function withProfiling(): self
78
    {
79
        $this->inner()->enableProfiler();
0 ignored issues
show
Bug introduced by
The method enableProfiler() does not exist on Symfony\Component\BrowserKit\AbstractBrowser. It seems like you code against a sub-type of Symfony\Component\BrowserKit\AbstractBrowser such as Symfony\Bundle\FrameworkBundle\KernelBrowser. ( Ignorable by Annotation )

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

79
        $this->inner()->/** @scrutinizer ignore-call */ enableProfiler();
Loading history...
80
81
        return $this;
82
    }
83
84
    public function actingAs(UserInterface $user, ?string $firewall = null): self
85
    {
86
        $this->inner()->loginUser(...\array_filter([$user, $firewall]));
0 ignored issues
show
Bug introduced by
The method loginUser() does not exist on Symfony\Component\BrowserKit\AbstractBrowser. It seems like you code against a sub-type of Symfony\Component\BrowserKit\AbstractBrowser such as Symfony\Bundle\FrameworkBundle\KernelBrowser. ( Ignorable by Annotation )

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

86
        $this->inner()->/** @scrutinizer ignore-call */ loginUser(...\array_filter([$user, $firewall]));
Loading history...
87
88
        return $this;
89
    }
90
91
    final public function profile(): Profile
92
    {
93
        if (!$profile = $this->inner()->getProfile()) {
0 ignored issues
show
Bug introduced by
The method getProfile() does not exist on Symfony\Component\BrowserKit\AbstractBrowser. It seems like you code against a sub-type of Symfony\Component\BrowserKit\AbstractBrowser such as Symfony\Bundle\FrameworkBundle\KernelBrowser. ( Ignorable by Annotation )

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

93
        if (!$profile = $this->inner()->/** @scrutinizer ignore-call */ getProfile()) {
Loading history...
94
            throw new \RuntimeException('Profiler not enabled for this request. Try calling ->withProfiling() before the request.');
95
        }
96
97
        return $profile;
98
    }
99
}
100