Completed
Push — master ( 62eba7...9fc3a4 )
by Márk
08:43 queued 05:59
created

DiactorosMessageFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 47
ccs 14
cts 14
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createRequest() 0 14 1
A createResponse() 0 13 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