Completed
Push — master ( ad34f0...67a90e )
by Stefano
32s
created

src/RequestLocation/BodyLocation.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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()];
41 1
        $value = $param->getName() . '=' . $param->filter($value);
0 ignored issues
show
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