Completed
Push — master ( d8465d...85c396 )
by Stefano
03:17
created

MultiPartLocation::visit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 13
cts 13
cp 1
rs 9.2
c 0
b 0
f 0
cc 2
eloc 14
nc 2
nop 3
crap 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\RequestInterface;
8
9
/**
10
 * Adds POST files to a request
11
 */
12
class MultiPartLocation extends AbstractLocation
13
{
14
    /** @var string $contentType */
15
    protected $contentType = 'multipart/form-data; boundary=';
16
17
    /** @var array $formParamsData */
18
    protected $multipartData = [];
19
20
    /**
21
     * Set the name of the location
22
     *
23
     * @param string $locationName
24
     */
25 1
    public function __construct($locationName = 'multipart')
26
    {
27 1
        parent::__construct($locationName);
28 1
    }
29
30
    /**
31
     * @param CommandInterface $command
32
     * @param RequestInterface $request
33
     * @param Parameter $param
34
     * @return RequestInterface
35
     */
36 1
    public function visit(
37
        CommandInterface $command,
38
        RequestInterface $request,
39
        Parameter $param
40
    ) {
41 1
        $modify = [];
42
43 1
        $this->multipartData['multipart'] = [
44 1
            'name' => $param->getWireName(),
45 1
            'contents' => $this->prepareValue($command[$param->getName()], $param)
0 ignored issues
show
Bug introduced by
Consider using $param->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
46 1
        ];
47
48 1
        $body = new Psr7\MultipartStream($this->multipartData);
49 1
        $modify['body'] = Psr7\stream_for($body);
50 1
        $request = Psr7\modify_request($request, $modify);
51 1
        if ($request->getBody() instanceof Psr7\MultipartStream) {
0 ignored issues
show
Bug introduced by
The class GuzzleHttp\Psr7\MultipartStream does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
52
            // Use a multipart/form-data POST if a Content-Type is not set.
53 1
            $request->withHeader('Content-Type', $this->contentType . $request->getBody()->getBoundary());
54 1
        }
55
56 1
        return $request;
57
    }
58
}
59