RequestFactory::createRequest()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.2098

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 4
nop 2
dl 0
loc 14
ccs 5
cts 7
cp 0.7143
crap 3.2098
rs 10
c 0
b 0
f 0
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