BodyLocation::__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\Parameter;
6
use GuzzleHttp\Psr7;
7
use Psr\Http\Message\MessageInterface;
8
use Psr\Http\Message\RequestInterface;
9
10
/**
11
 * Adds a body to a request
12
 */
13
class BodyLocation extends AbstractLocation
14
{
15
16
    /**
17
     * Set the name of the location
18
     *
19
     * @param string $locationName
20
     */
21 1
    public function __construct($locationName = 'body')
22
    {
23 1
        parent::__construct($locationName);
24 1
    }
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
        $oldValue = $request->getBody()->getContents();
39
40 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...
41 1
        $value = $param->getName() . '=' . $param->filter($value);
0 ignored issues
show
Bug introduced by
Consider using $param->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
42
43 1
        if ($oldValue !== '') {
44
            $value = $oldValue . '&' . $value;
45
        }
46
47 1
        return $request->withBody(Psr7\stream_for($value));
48
    }
49
}
50