Passed
Push — master ( 0fd05a...7bafc9 )
by Thomas
01:51
created

src/Factory/NyholmFactory.php (1 issue)

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\UploadedFileInterface;
12
use Psr\Http\Message\UriInterface;
13
14
class NyholmFactory implements FactoryInterface
15
{
16
17
    /** @var Psr17Factory */
18
    private $factory;
19
20
    /**
21
     * NyholmFactory constructor.
22
     */
23
    public function __construct()
24
    {
25
        $this->factory = new Psr17Factory();
26
    }
27
28
    /**
29
     * Check whether Nyholm PSR-7 is available
30
     */
31
    public static function isInstalled(): bool
32
    {
33
        return class_exists('Nyholm\\Psr7\\Factory\\Psr17Factory');
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
40
    {
41
        return $this->factory->createResponse($code, $reasonPhrase);
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47
    public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface
48
    {
49
        return $this->factory->createServerRequest($method, $uri, $serverParams);
50
    }
51
52
    /**
53
     * @inheritdoc
54
     */
55
    public function createServerRequestFromGlobals(): ServerRequestInterface
56
    {
57
        // TODO: Implement createServerRequestFromGlobals() method.
58
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Psr\Http\Message\ServerRequestInterface. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
59
60
    /**
61
     * @inheritdoc
62
     */
63
    public function createStream(string $content = ''): StreamInterface
64
    {
65
        return $this->factory->createStream($content);
66
    }
67
68
    /**
69
     * @inheritdoc
70
     */
71
    public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
72
    {
73
        return $this->factory->createStreamFromFile($filename, $mode);
74
    }
75
76
    /**
77
     * @inheritdoc
78
     */
79
    public function createStreamFromResource($resource): StreamInterface
80
    {
81
        return $this->factory->createStreamFromResource($resource);
82
    }
83
84
    /**
85
     * @inheritdoc
86
     */
87
    public function createUri(string $uri = ''): UriInterface
88
    {
89
        return $this->factory->createUri($uri);
90
    }
91
92
    /**
93
     * @inheritdoc
94
     */
95
    public function createUploadedFile(
96
        StreamInterface $stream,
97
        int $size = null,
98
        int $error = \UPLOAD_ERR_OK,
99
        string $clientFilename = null,
100
        string $clientMediaType = null
101
    ): UploadedFileInterface {
102
        return $this->factory->createUploadedFile($stream, $size, $error, $clientFilename, $clientMediaType);
103
    }
104
}
105