BodyLocation   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 37
ccs 9
cts 11
cp 0.8182
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A visit() 0 16 2
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