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

HttplugFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 0
loc 26
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createRequest() 0 4 1
A createResponse() 0 4 1
A createStream() 0 4 2
A createUri() 0 8 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