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

src/Factory/HttplugFactory.php (3 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, Stream, Uri};
8
use Psr\Http\Message\UriInterface;
9
use Http\Message\{MessageFactory, StreamFactory, UriFactory};
10
11
/**
12
 * @author Tobias Nyholm <[email protected]>
13
 * @author Martijn van der Ven <[email protected]>
14
 */
15
final class HttplugFactory implements MessageFactory, StreamFactory, UriFactory
16
{
17
    public function createRequest($method, $uri, array $headers = [], $body = null, $protocolVersion = '1.1')
18
    {
19
        return new Request($method, $uri, $headers, $body, $protocolVersion);
1 ignored issue
show
It seems like $uri defined by parameter $uri on line 17 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...
It seems like $body defined by parameter $body on line 17 can also be of type object<Psr\Http\Message\StreamInterface>; however, Nyholm\Psr7\Request::__construct() does only seem to accept string|null|resource|object<StreamInterface>, 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...
20
    }
21
22
    public function createResponse($statusCode = 200, $reasonPhrase = null, array $headers = [], $body = null, $version = '1.1')
23
    {
24
        return new Response((int) $statusCode, $headers, $body, $version, $reasonPhrase);
0 ignored issues
show
It seems like $body defined by parameter $body on line 22 can also be of type object<Psr\Http\Message\StreamInterface>; however, Nyholm\Psr7\Response::__construct() does only seem to accept string|null|resource|object<StreamInterface>, 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...
25
    }
26
27
    public function createStream($body = null)
28
    {
29
        return Stream::create(null === $body ? '' : $body);
30
    }
31
32
    public function createUri($uri = ''): UriInterface
33
    {
34
        if ($uri instanceof UriInterface) {
35
            return $uri;
36
        }
37
38
        return new Uri($uri);
39
    }
40
}
41