SlimMessageFactory::createRequest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 5
dl 0
loc 16
ccs 9
cts 9
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Http\Message\MessageFactory;
4
5
use Http\Message\MessageFactory;
6
use Http\Message\StreamFactory\SlimStreamFactory;
7
use Http\Message\UriFactory\SlimUriFactory;
8
use Slim\Http\Headers;
9
use Slim\Http\Request;
10
use Slim\Http\Response;
11
12
/**
13
 * Creates Slim 3 messages.
14
 *
15
 * @author Mika Tuupola <[email protected]>
16
 *
17
 * @deprecated This will be removed in php-http/message2.0. Consider using the official Slim PSR-17 factory
18
 */
19
final class SlimMessageFactory implements MessageFactory
20
{
21
    /**
22
     * @var SlimStreamFactory
23
     */
24
    private $streamFactory;
25
26
    /**
27
     * @var SlimUriFactory
28
     */
29 4
    private $uriFactory;
30
31 4
    public function __construct()
32 4
    {
33 4
        $this->streamFactory = new SlimStreamFactory();
0 ignored issues
show
Deprecated Code introduced by
The class Http\Message\StreamFactory\SlimStreamFactory has been deprecated: This will be removed in php-http/message2.0. Consider using the official Slim PSR-17 factory ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

33
        $this->streamFactory = /** @scrutinizer ignore-deprecated */ new SlimStreamFactory();
Loading history...
34
        $this->uriFactory = new SlimUriFactory();
0 ignored issues
show
Deprecated Code introduced by
The class Http\Message\UriFactory\SlimUriFactory has been deprecated: This will be removed in php-http/message2.0. Consider using the official Slim PSR-17 factory ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

34
        $this->uriFactory = /** @scrutinizer ignore-deprecated */ new SlimUriFactory();
Loading history...
35
    }
36
37
    /**
38 1
     * {@inheritdoc}
39
     */
40
    public function createRequest(
41
        $method,
42
        $uri,
43
        array $headers = [],
44
        $body = null,
45 1
        $protocolVersion = '1.1'
46 1
    ) {
47 1
        return (new Request(
48 1
            $method,
49 1
            $this->uriFactory->createUri($uri),
50 1
            new Headers($headers),
51 1
            [],
52 1
            [],
53 1
            $this->streamFactory->createStream($body),
54
            []
55
        ))->withProtocolVersion($protocolVersion);
56
    }
57
58
    /**
59 1
     * {@inheritdoc}
60
     */
61
    public function createResponse(
62
        $statusCode = 200,
63
        $reasonPhrase = null,
64
        array $headers = [],
65
        $body = null,
66 1
        $protocolVersion = '1.1'
67 1
    ) {
68 1
        return (new Response(
69 1
            $statusCode,
70 1
            new Headers($headers),
71
            $this->streamFactory->createStream($body)
72
        ))->withProtocolVersion($protocolVersion);
73
    }
74
}
75