Failed Conditions
Push — feature/improve ( ac6d69...acfd74 )
by Yo
02:11
created

Client::doRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 9
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
crap 6
1
<?php
2
namespace Yoanm\Behat3SymfonyExtension\Client;
3
4
use Symfony\Bundle\FrameworkBundle\Client as BaseClient;
5
use Symfony\Component\BrowserKit\CookieJar;
6
use Symfony\Component\BrowserKit\History;
7
use Symfony\Component\HttpKernel\KernelInterface;
8
use Yoanm\Behat3SymfonyExtension\Handler\KernelHandler;
9
10
class Client extends BaseClient
11
{
12
    /** @var KernelHandler */
13
    private $kernelHandler;
14
    /** @var bool */
15
    private $requestPerformed = false;
16
    /**
17
     * @inheritDoc
18
     */
19
    public function __construct(
20
        KernelHandler $kernelHandler,
21
        KernelInterface $kernel,
22
        array $server,
23
        History $history,
24
        CookieJar $cookieJar
25
    ) {
26
        parent::__construct($kernel, $server, $history, $cookieJar);
27
        $this->kernelHandler = $kernelHandler;
28
        $this->disableReboot();
29
    }
30
31
    /**
32
     * @return boolean
33
     */
34
    public function hasRequestPerformed()
35
    {
36
        return $this->requestPerformed;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    protected function doRequest($request)
43
    {
44
        if ($this->requestPerformed) {
45
            // Reboot sfKernel to avoid parent::doRequest to shutdown it and from Kernel::handle to boot it
46
            $this->kernelHandler->rebootSfKernel();
47
        } else {
48
            $this->requestPerformed = true;
49
        }
50
51
        return parent::doRequest($request);
52
    }
53
}
54