Passed
Push — main ( a1a461...2097df )
by Thomas
12:50
created

Nyholm::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Conia\Chuck\Psr;
6
7
use Conia\Chuck\Exception\RuntimeException;
8
use Nyholm\Psr7\Factory\Psr17Factory;
9
use Nyholm\Psr7Server\ServerRequestCreator;
10
use Psr\Http\Message\ServerRequestInterface as PsrServerRequest;
11
use Throwable;
12
13
class Nyholm extends AbstractFactory
14
{
15
    protected Psr17Factory $factory;
16
17 75
    public function __construct()
18
    {
19
        try {
20 75
            $this->factory = $this->streamFactory = $this->responseFactory = new Psr17Factory();
21
            // @codeCoverageIgnoreStart
22
        } catch (Throwable) {
23
            throw new RuntimeException('Install laminas/laminas-diactoros');
24
            // @codeCoverageIgnoreEnd
25
        }
26
    }
27
28 11
    public function request(): PsrServerRequest
29
    {
30 11
        $creator = new ServerRequestCreator(
31 11
            $this->factory, // ServerRequestFactory
32 11
            $this->factory, // UriFactory
33 11
            $this->factory, // UploadedFileFactory
34 11
            $this->factory  // StreamFactory
35 11
        );
36
37 11
        return $creator->fromGlobals();
38
    }
39
}
40