HeaderLocation::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
namespace GuzzleHttp\Command\Guzzle\RequestLocation;
3
4
use GuzzleHttp\Command\CommandInterface;
5
use GuzzleHttp\Command\Guzzle\Operation;
6
use GuzzleHttp\Command\Guzzle\Parameter;
7
use Psr\Http\Message\MessageInterface;
8
use Psr\Http\Message\RequestInterface;
9
10
/**
11
 * Request header location
12
 */
13
class HeaderLocation extends AbstractLocation
14
{
15
16
    /**
17
     * Set the name of the location
18
     *
19
     * @param string $locationName
20
     */
21 2
    public function __construct($locationName = 'header')
22
    {
23 2
        parent::__construct($locationName);
24 2
    }
25
26
    /**
27
     * @param CommandInterface $command
28
     * @param RequestInterface $request
29
     * @param Parameter        $param
30
     *
31
     * @return MessageInterface
32
     */
33 1
    public function visit(
34
        CommandInterface $command,
35
        RequestInterface $request,
36
        Parameter $param
37
    ) {
38 1
        $value = $command[$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...
39
40 1
        return $request->withHeader($param->getWireName(), $param->filter($value));
41
    }
42
43
    /**
44
     * @param CommandInterface $command
45
     * @param RequestInterface $request
46
     * @param Operation        $operation
47
     *
48
     * @return RequestInterface
49
     */
50 1
    public function after(
51
        CommandInterface $command,
52
        RequestInterface $request,
53
        Operation $operation
54
    ) {
55
        /** @var Parameter $additional */
56 1
        $additional = $operation->getAdditionalParameters();
57 1 View Code Duplication
        if ($additional && ($additional->getLocation() === $this->locationName)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58 1
            foreach ($command->toArray() as $key => $value) {
59 1
                if (!$operation->hasParam($key)) {
60 1
                    $request = $request->withHeader($key, $additional->filter($value));
61 1
                }
62 1
            }
63 1
        }
64
65 1
        return $request;
66
    }
67
}
68