ServerRequestFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 28
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createServerRequest() 0 7 2
A createServerRequestFromArray() 0 7 2
1
<?php
2
namespace DevOp\Core\Http;
3
4
use DevOp\Core\Http\ServerRequest;
5
use Psr\Http\Message\UriInterface;
6
use Psr\Http\Message\ServerRequestFactoryInterface;
7
8
class ServerRequestFactory implements ServerRequestFactoryInterface
9
{
10
11
    /**
12
     * @param string $method
13
     * @param UriInterface $uri
14
     * @return ServerRequest
15
     */
16
    public function createServerRequest($method, $uri)
17
    {
18
        if (!$uri instanceof UriInterface) {
0 ignored issues
show
introduced by
$uri is always a sub-type of Psr\Http\Message\UriInterface.
Loading history...
19
            $uri = new Uri($uri);
20
        }
21
22
        return new ServerRequest($method, $uri);
23
    }
24
25
    /**
26
     * @param array $server
27
     * @return ServerRequest
28
     */
29
    public function createServerRequestFromArray(array $server)
30
    {
31
        $method = $server['REQUEST_METHOD'] ?: 'GET';
32
        $uri = ServerRequest::getUriFromGlobals($server);
33
        $body = (new StreamFactory())->createStreamFromFile('php://temp', 'r+');
34
35
        return new ServerRequest($method, $uri, $server, $body, '1.1');
36
    }
37
}
38