RequestFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 24
ccs 5
cts 7
cp 0.7143
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 Psr\Http\Message\RequestFactoryInterface;
6
7
class RequestFactory implements RequestFactoryInterface
8
{
9
10
    /**
11
     * 
12
     * @param string $method
13
     * @param \Psr\Http\Message\UriInterface|string $uri
14
     * @return Request
15
     * @throws \InvalidArgumentException
16
     */
17 20
    public function createRequest(string $method, $uri): \Psr\Http\Message\RequestInterface
18
    {
19
20 20
        if (is_string($uri)) {
21
            $uri = (new UriFactory())->createUri($uri);
22
        }
23
24 20
        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...
25
            throw new \InvalidArgumentException('URI must be a instance of ' . \Psr\Http\Message\UriInterface::class);
26
        }
27
28 20
        $body = (new StreamFactory())->createStream('');
29
30 20
        return new Request($method, $uri, [], $body);
31
    }
32
}
33