Goutte   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 38
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 7 1
A setHttpHeader() 0 14 2
A resetHttpHeaders() 0 4 1
1
<?php
2
3
namespace Behatch\HttpCall\Request;
4
5
class Goutte extends BrowserKit
6
{
7
    /**
8
     * headers are no more stored on client, because client does not flush them when reset/restart session.
9
     * They are on Behat\Mink\Driver\BrowserKitDriver and there is no way to get them.
10
     *
11
     * @var array
12
     */
13
    private $requestHeaders = [];
14
15
    public function send($method, $url, $parameters = [], $files = [], $content = null, $headers = [])
16
    {
17
        $page = parent::send($method, $url, $parameters, $files, $content, array_merge($headers, $this->requestHeaders));
18
        $this->resetHttpHeaders();
19
20
        return $page;
21
    }
22
23
    public function setHttpHeader($name, $value)
24
    {
25
        /* taken from Behat\Mink\Driver\BrowserKitDriver::setRequestHeader */
26
        $contentHeaders = array('CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true);
27
        $name = str_replace('-', '_', strtoupper($name));
28
29
        // CONTENT_* are not prefixed with HTTP_ in PHP when building $_SERVER
30
        if (!isset($contentHeaders[$name])) {
31
            $name = 'HTTP_' . $name;
32
        }
33
        /* taken from Behat\Mink\Driver\BrowserKitDriver::setRequestHeader */
34
35
        $this->requestHeaders[$name] = $value;
36
    }
37
38
    protected function resetHttpHeaders()
39
    {
40
        $this->requestHeaders = [];
41
    }
42
}
43