RequestFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 14
c 0
b 0
f 0
dl 0
loc 41
ccs 17
cts 17
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromNew() 0 3 1
A createRequest() 0 19 1
1
<?php
2
/**
3
 * This file is part of the Shieldon package.
4
 *
5
 * (c) Terry L. <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace Shieldon\Psr17;
14
15
use Psr\Http\Message\RequestFactoryInterface;
16
use Psr\Http\Message\RequestInterface;
17
use Shieldon\Psr17\UriFactory;
18
use Shieldon\Psr17\StreamFactory;
19
use Shieldon\Psr17\Utils\SuperGlobal;
20
use Shieldon\Psr7\Request;
21
22
use function str_replace;
23
use function extract;
24
25
/**
26
 * PSR-17 Request Factory
27
 */
28
class RequestFactory implements RequestFactoryInterface
29
{
30
    /**
31
     * {@inheritdoc}
32
     */
33 1
    public function createRequest(string $method, $uri): RequestInterface
34
    {
35 1
        extract(SuperGlobal::extract());
36
37 1
        $protocol = $server['SERVER_PROTOCOL'] ?? '1.1';
38 1
        $protocol = str_replace('HTTP/', '',  $protocol);
39
40 1
        $uriFactory = new UriFactory();
41 1
        $streamFactory = new StreamFactory();
42
43 1
        $uri = $uriFactory->createUri($uri);
44 1
        $body = $streamFactory->createStream();
45
46 1
        return new Request(
47 1
            $method,
48 1
            $uri,
49 1
            $body,
50 1
            $header, // from extract.
51 1
            $protocol
52 1
        );
53
    }
54
55
    /*
56
    |--------------------------------------------------------------------------
57
    | Non PSR-7 Methods.
58
    |--------------------------------------------------------------------------
59
    */
60
61
    /**
62
     * Create a new Request.
63
     *
64
     * @return RequestInterface
65
     */
66 1
    public static function fromNew(): RequestInterface
67
    {
68 1
        return new Request();
69
    }
70
}
71