Passed
Push — master ( b65012...5ddc87 )
by Zlatin
01:29
created

RequestFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A createRequest() 0 14 3
1
<?php
2
namespace DevOp\Core\Http;
3
4
use DevOp\Core\Http\Request;
5
use Interop\Http\Factory\RequestFactoryInterface;
6
7
class RequestFactory implements RequestFactoryInterface
8
{
9
10
    /**
11
     * @param string $method
12
     * @param string|\Psr\Http\Message\UriInterface $uri
13
     * @return Request
14
     * @throws \InvalidArgumentException
15
     */
16 34
    public function createRequest($method, $uri)
17
    {
18
19 34
        if (is_string($uri)) {
20 12
            $uri = (new UriFactory())->createUri($uri);
21
        }
22
23 34
        if (!$uri instanceof \Psr\Http\Message\UriInterface) {
0 ignored issues
show
introduced by
$uri is always a sub-type of Psr\Http\Message\UriInterface.
Loading history...
24
            throw new \InvalidArgumentException('URI must be a instance of ' . \Psr\Http\Message\UriInterface::class);
25
        }
26
27 34
        $body = (new StreamFactory())->createStream('');
28
29 34
        return new Request($method, $uri, [], $body);
30
    }
31
}
32