Completed
Push — master ( acde7d...51a0aa )
by Tobias
03:21
created

SlimMessageFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 56
ccs 0
cts 35
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A createRequest() 0 17 1
A createResponse() 0 13 1
1
<?php
2
3
namespace Http\Message\MessageFactory;
4
5
use Http\Message\StreamFactory\SlimStreamFactory;
6
use Http\Message\UriFactory\SlimUriFactory;
7
use Http\Message\MessageFactory;
8
use Slim\Http\Request;
9
use Slim\Http\Response;
10
use Slim\Http\Headers;
11
12
/**
13
 * Creates Slim 3 messages.
14
 *
15
 * @author Mika Tuupola <[email protected]>
16
 */
17
final class SlimMessageFactory implements MessageFactory
18
{
19
    /**
20
     * @var SlimStreamFactory
21
     */
22
    private $streamFactory;
23
24
    /**
25
     * @var SlimUriFactory
26
     */
27
    private $uriFactory;
28
29
    public function __construct()
30
    {
31
        $this->streamFactory = new SlimStreamFactory();
32
        $this->uriFactory = new SlimUriFactory();
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function createRequest(
39
        $method,
40
        $uri,
41
        array $headers = [],
42
        $body = null,
43
        $protocolVersion = '1.1'
44
    ) {
45
        return (new Request(
46
            $method,
47
            $this->uriFactory->createUri($uri),
48
            new Headers($headers),
49
            [],
50
            [],
51
            $this->streamFactory->createStream($body),
52
            []
53
        ))->withProtocolVersion($protocolVersion);
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function createResponse(
60
        $statusCode = 200,
61
        $reasonPhrase = null,
62
        array $headers = [],
63
        $body = null,
64
        $protocolVersion = '1.1'
65
    ) {
66
        return (new Response(
67
            $statusCode,
68
            new Headers($headers),
69
            $this->streamFactory->createStream($body)
70
        ))->withProtocolVersion($protocolVersion);
71
    }
72
}
73