HeaderLocation::visit()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 9.7333
c 0
b 0
f 0
cc 3
nc 3
nop 3
crap 3
1
<?php
2
namespace GuzzleHttp\Command\Guzzle\ResponseLocation;
3
4
use GuzzleHttp\Command\Guzzle\Parameter;
5
use GuzzleHttp\Command\ResultInterface;
6
use Psr\Http\Message\ResponseInterface;
7
8
/**
9
 * Extracts headers from the response into a result fields
10
 */
11
class HeaderLocation extends AbstractLocation
12
{
13
14
    /**
15
     * Set the name of the location
16
     *
17
     * @param string $locationName
18
     */
19 1
    public function __construct($locationName = 'header')
20
    {
21 1
        parent::__construct($locationName);
22 1
    }
23
24
    /**
25
     * @param ResultInterface   $result
26
     * @param ResponseInterface $response
27
     * @param Parameter         $param
28
     *
29
     * @return ResultInterface
30
     */
31 1
    public function visit(
32
        ResultInterface $result,
33
        ResponseInterface $response,
34
        Parameter $param
35
    ) {
36
        // Retrieving a single header by name
37 1
        $name = $param->getName();
0 ignored issues
show
Bug introduced by
Consider using $param->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
38 1
        if ($header = $response->getHeader($param->getWireName())) {
39 1
            if (is_array($header)) {
40 1
                $header = array_shift($header);
41 1
            }
42 1
            $result[$name] = $param->filter($header);
43 1
        }
44
45 1
        return $result;
46
    }
47
}
48