ServerRequestFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createServerRequest() 0 4 1
A fromGlobals() 0 20 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Furious\Psr7\Factory;
6
7
use Furious\Psr7\Header\HeadersCollection;
8
use Furious\Psr7\Protocol\Protocol;
9
use Furious\Psr7\ServerRequest;
10
use Psr\Http\Message\ServerRequestFactoryInterface;
11
use Psr\Http\Message\ServerRequestInterface;
12
13
class ServerRequestFactory implements ServerRequestFactoryInterface
14
{
15
    public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface
16
    {
17
        return new ServerRequest($method, $uri,'1.1', [], [], [], $serverParams);
18
    }
19
20
    public function fromGlobals(): ServerRequest
21
    {
22
        $method = $_SERVER['REQUEST_METHOD'] ?? 'GET';
23
        $uri = $_SERVER['REQUEST_URI'] ?? '';
24
        $protocolVersion = (new Protocol())->getVersion($_SERVER);
25
        $headers = (new HeadersCollection($_SERVER))->get();
26
        $body = 'php://input';
27
28
        return new ServerRequest(
29
            $method,
30
            $uri,
31
            $protocolVersion,
32
            $headers,
33
            $_GET,
34
            $body,
35
            $_SERVER,
36
            $_COOKIE,
37
            $_FILES, []
38
        );
39
    }
40
}