Completed
Pull Request — master (#325)
by
unknown
01:32
created

BigPipeContext::prepareBigPipeNoJsCookie()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 0
1
<?php
2
3
namespace Drupal\DrupalExtension\Context;
4
5
use Drupal\big_pipe\Render\Placeholder\BigPipeStrategy;
6
use Behat\Mink\Exception\UnsupportedDriverActionException;
7
8
/**
9
 * Big Pipe context.
10
 */
11
class BigPipeContext extends RawDrupalContext {
12
13
    /**
14
     * Prepares Big Pipe NOJS cookie if needed.
15
     *
16
     * @BeforeScenario
17
     */
18
    public function prepareBigPipeNoJsCookie()
19
    {
20
        try {
21
            // Check if JavaScript can be executed by Driver.
22
            $this->getSession()->getDriver()->executeScript('true');
23
        }
24
        catch (UnsupportedDriverActionException $e) {
25
            // Set NOJS cookie.
26
            $this
27
              ->getSession()
28
              ->setCookie(BigPipeStrategy::NOJS_COOKIE, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
29
30
        }
31
        catch (\Exception $e) {
32
            // Mute exceptions.
33
        }
34
    }
35
36
}
37