Completed
Push — develop ( c8d2e9...9b1d71 )
by Adam
03:00
created

RequestBuilder::createMultipartStreamRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 4
1
<?php
2
3
namespace IBM\Watson\Common;
4
5
use Http\Message\RequestFactory;
6
use IBM\Watson\Common\Util\DiscoveryTrait;
7
8
/**
9
 * Interface to build PSR-7 request
10
 */
11
class RequestBuilder
12
{
13
    use DiscoveryTrait;
14
15
    /**
16
     * @var \Http\Message\MessageFactory
17
     */
18
    private $requestFactory;
19
20
    /**
21
     * @param \Http\Message\RequestFactory $requestFactory
22
     */
23
    public function __construct(RequestFactory $requestFactory = null)
24
    {
25
        $this->requestFactory = $requestFactory ?: $this->discoverMessageFactory();
0 ignored issues
show
Documentation Bug introduced by
$requestFactory ?: $this...iscoverMessageFactory() is of type object<Http\Message\RequestFactory>, but the property $requestFactory was declared to be of type object<Http\Message\MessageFactory>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
26
    }
27
28
    /**
29
     * Create a new PSR-7 request.
30
     *
31
     * @param string                               $method
32
     * @param string|UriInterface                  $uri
33
     * @param array                                $headers
34
     * @param resource|string|StreamInterface|null $body
35
     *
36
     * @return \Psr\Http\Message\RequestInterface
37
     */
38
    public function create($method, $uri, array $headers = [], $body = null)
39
    {
40
        return $this->requestFactory->createRequest($method, $uri, $headers, $body);
41
    }
42
}
43