Completed
Push — master ( 905e92...9a896f )
by Tobias
02:28
created

src/Factory/Psr17Factory.php (2 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nyholm\Psr7\Factory;
6
7
use Nyholm\Psr7\{Request, Response, ServerRequest, Stream, UploadedFile, Uri};
8
use Psr\Http\Message\{RequestFactoryInterface, RequestInterface, ResponseFactoryInterface, ResponseInterface, ServerRequestFactoryInterface, ServerRequestInterface, StreamFactoryInterface, StreamInterface, UploadedFileFactoryInterface, UploadedFileInterface, UriFactoryInterface, UriInterface};
9
10
/**
11
 * @author Tobias Nyholm <[email protected]>
12
 * @author Martijn van der Ven <[email protected]>
13
 */
14
final class Psr17Factory implements RequestFactoryInterface, ResponseFactoryInterface, ServerRequestFactoryInterface, StreamFactoryInterface, UploadedFileFactoryInterface, UriFactoryInterface
15
{
16 7
    public function createRequest(string $method, $uri): RequestInterface
17
    {
18 7
        return new Request($method, $uri);
1 ignored issue
show
It seems like $uri defined by parameter $uri on line 16 can also be of type object<Psr\Http\Message\UriInterface>; however, Nyholm\Psr7\Request::__construct() does only seem to accept string|object<UriInterface>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
19
    }
20
21 4
    public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
22
    {
23 4
        return new Response($code, [], null, '1.1', $reasonPhrase);
24
    }
25
26 6
    public function createStream(string $content = ''): StreamInterface
27
    {
28 6
        return Stream::create($content);
29
    }
30
31 1
    public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
32
    {
33 1
        return Stream::create(fopen($filename, $mode));
34
    }
35
36 1
    public function createStreamFromResource($resource): StreamInterface
37
    {
38 1
        return Stream::create($resource);
39
    }
40
41 12
    public function createUploadedFile(StreamInterface $stream, int $size = null, int $error = \UPLOAD_ERR_OK, string $clientFilename = null, string $clientMediaType = null): UploadedFileInterface
42
    {
43 12
        if (null === $size) {
44 12
            $size = $stream->getSize();
45
        }
46
47 12
        return new UploadedFile($stream, $size, $error, $clientFilename, $clientMediaType);
48
    }
49
50 13
    public function createUri(string $uri = ''): UriInterface
51
    {
52 13
        return new Uri($uri);
53
    }
54
55 23
    public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface
56
    {
57 23
        return new ServerRequest($method, $uri, [], null, '1.1', $serverParams);
1 ignored issue
show
It seems like $uri defined by parameter $uri on line 55 can also be of type object<Psr\Http\Message\UriInterface>; however, Nyholm\Psr7\ServerRequest::__construct() does only seem to accept string|object<UriInterface>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
58
    }
59
}
60