Completed
Pull Request — master (#2)
by Márk
02:43
created

DiactorosMessageFactory::createResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 13
ccs 5
cts 5
cp 1
rs 9.4286
cc 1
eloc 11
nc 1
nop 5
crap 1
1
<?php
2
3
namespace Http\Message\MessageFactory;
4
5
use Http\Message\StreamFactory\DiactorosStreamFactory;
6
use Http\Message\MessageFactory;
7
use Zend\Diactoros\Request;
8
use Zend\Diactoros\Response;
9
10
/**
11
 * Creates Diactoros messages.
12
 *
13
 * @author GeLo <[email protected]>
14
 */
15
final class DiactorosMessageFactory implements MessageFactory
16
{
17
    /**
18
     * @var DiactorosStreamFactory
19
     */
20
    private $streamFactory;
21
22 4
    public function __construct()
23
    {
24 4
        $this->streamFactory = new DiactorosStreamFactory();
25 4
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 1
    public function createRequest(
31
        $method,
32
        $uri,
33
        array $headers = [],
34
        $body = null,
35
        $protocolVersion = '1.1'
36
    ) {
37 1
        return (new Request(
38 1
            $uri,
0 ignored issues
show
Bug introduced by
It seems like $uri defined by parameter $uri on line 32 can also be of type object<Psr\Http\Message\UriInterface>; however, Zend\Diactoros\Request::__construct() does only seem to accept null|string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
39 1
            $method,
40 1
            $this->streamFactory->createStream($body),
41
            $headers
42 1
        ))->withProtocolVersion($protocolVersion);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 1
    public function createResponse(
49
        $statusCode = 200,
50
        $reasonPhrase = null,
51
        array $headers = [],
52
        $body = null,
53
        $protocolVersion = '1.1'
54
    ) {
55 1
        return (new Response(
56 1
            $this->streamFactory->createStream($body),
57 1
            $statusCode,
58
            $headers
59 1
        ))->withProtocolVersion($protocolVersion);
60
    }
61
}
62