Completed
Pull Request — master (#16)
by Sergii
07:37
created

RawRedirectContext   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 23
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getStatusCode() 0 14 2
1
<?php
2
/**
3
 * @author Sergii Bondarenko, <[email protected]>
4
 */
5
namespace Drupal\TqExtension\Context\Redirect;
6
7
// Contexts.
8
use Drupal\TqExtension\Context\RawTqContext;
9
// Utils.
10
use Behat\Mink\Driver\GoutteDriver;
11
12
class RawRedirectContext extends RawTqContext
13
{
14
    /**
15
     * @param string $path
16
     *   An URL to visit (relative or absolute).
17
     *
18
     * @return int
19
     */
20
    public function getStatusCode($path)
21
    {
22
        // The "Goutte" session should be used because it provides HTTP status codes.
23
        // Visit path once again if current session driver is not Goutte.
24
        if (!($this->getSessionDriver() instanceof GoutteDriver)) {
25
            $this->visitPath($path, 'goutte');
26
        }
27
28
        $statusCode = (int) $this->getSession('goutte')->getStatusCode();
29
30
        self::debug(['HTTP status code: %s'], [$statusCode]);
31
32
        return $statusCode;
33
    }
34
}
35