Completed
Push — master ( 19a34e...c0ac45 )
by Tobias
02:27
created

HttplugFactory::createRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 5
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nyholm\Psr7\Factory;
6
7
use Nyholm\Psr7\Request;
8
use Nyholm\Psr7\Response;
9
use Nyholm\Psr7\Stream;
10
use Nyholm\Psr7\Uri;
11
use Psr\Http\Message\UriInterface;
12
13
/**
14
 * @author Tobias Nyholm <[email protected]>
15
 * @author Martijn van der Ven <[email protected]>
16
 */
17
final class HttplugFactory implements \Http\Message\MessageFactory, \Http\Message\StreamFactory, \Http\Message\UriFactory
18
{
19
    public function createRequest($method, $uri, array $headers = [], $body = null, $protocolVersion = '1.1')
20
    {
21
        return new Request($method, $uri, $headers, $body, $protocolVersion);
22
    }
23
24
    public function createResponse($statusCode = 200, $reasonPhrase = null, array $headers = [], $body = null, $version = '1.1')
25
    {
26
        return new Response((int) $statusCode, $headers, $body, $version, $reasonPhrase);
27
    }
28
29
    public function createStream($body = null)
30
    {
31
        return Stream::create(null === $body ? '' : $body);
32
    }
33
34
    public function createUri($uri = ''): UriInterface
35
    {
36
        if ($uri instanceof UriInterface) {
37
            return $uri;
38
        }
39
40
        return new Uri($uri);
41
    }
42
}
43