Passed
Push — master ( 76e439...0d9218 )
by Thomas
02:18
created

NyholmFactory::isInstalled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tebe\HttpFactory\Factory;
6
7
use Nyholm\Psr7\Factory\Psr17Factory;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
use Psr\Http\Message\StreamInterface;
11
use Psr\Http\Message\UriInterface;
12
13
class NyholmFactory implements FactoryInterface
14
{
15
16
    /** @var Psr17Factory */
17
    private $factory;
18
19
    /**
20
     * NyholmFactory constructor.
21
     */
22
    public function __construct()
23
    {
24
        $this->factory = new Psr17Factory();
25
    }
26
27
    /**
28
     * Check whether Nyholm PSR-7 is available
29
     */
30
    public static function isInstalled(): bool
31
    {
32
        return class_exists('Nyholm\\Psr7\\Factory\\Psr17Factory');
33
    }
34
35
    /**
36
     * @inheritdoc
37
     */
38
    public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
39
    {
40
        return $this->factory->createResponse($code, $reasonPhrase);
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46
    public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface
47
    {
48
        return $this->factory->createServerRequest($method, $uri, $serverParams);
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54
    public function createStream(string $content = ''): StreamInterface
55
    {
56
        return $this->factory->createStream($content);
57
    }
58
59
    /**
60
     * @inheritdoc
61
     */
62
    public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
63
    {
64
        return $this->factory->createStreamFromFile($filename, $mode);
65
    }
66
67
    /**
68
     * @inheritdoc
69
     */
70
    public function createStreamFromResource($resource): StreamInterface
71
    {
72
        return $this->factory->createStreamFromResource($resource);
73
    }
74
75
    /**
76
     * @inheritdoc
77
     */
78
    public function createUri(string $uri = ''): UriInterface
79
    {
80
        return $this->factory->createUri($uri);
81
    }
82
}
83