Passed
Push — master ( b65012...5ddc87 )
by Zlatin
01:29
created

ServerRequestFactory::createServerRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace DevOp\Core\Http;
3
4
use DevOp\Core\Http\ServerRequest;
5
use Psr\Http\Message\UriInterface;
6
use Interop\Http\Factory\ServerRequestFactoryInterface;
7
8
class ServerRequestFactory implements ServerRequestFactoryInterface
9
{
10
11
    /**
12
     * @param string $method
13
     * @param UriInterface $uri
14
     * @return ServerRequest
15
     */
16 32
    public function createServerRequest($method, $uri)
17
    {
18 32
        if (!$uri instanceof UriInterface) {
0 ignored issues
show
introduced by
$uri is always a sub-type of Psr\Http\Message\UriInterface.
Loading history...
19 20
            $uri = new Uri($uri);
20
        }
21
22 32
        return new ServerRequest($method, $uri);
0 ignored issues
show
Bug introduced by
$method of type string is incompatible with the type DevOp\Core\Http\type expected by parameter $method of DevOp\Core\Http\ServerRequest::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

22
        return new ServerRequest(/** @scrutinizer ignore-type */ $method, $uri);
Loading history...
23
    }
24
25
    /**
26
     * @param array $server
27
     * @return ServerRequest
28
     */
29 14
    public function createServerRequestFromArray(array $server)
30
    {
31 14
        $method = $server['REQUEST_METHOD'] ?: 'GET';
32 14
        $uri = ServerRequest::getUriFromGlobals($server);
33 14
        $body = (new StreamFactory())->createStreamFromFile('php://temp', 'r+');
34
35 14
        return new ServerRequest($method, $uri, $server, $body, '1.1');
0 ignored issues
show
Bug introduced by
'1.1' of type string is incompatible with the type DevOp\Core\Http\type expected by parameter $version of DevOp\Core\Http\ServerRequest::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        return new ServerRequest($method, $uri, $server, $body, /** @scrutinizer ignore-type */ '1.1');
Loading history...
Bug introduced by
It seems like $method can also be of type string; however, parameter $method of DevOp\Core\Http\ServerRequest::__construct() does only seem to accept DevOp\Core\Http\type, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        return new ServerRequest(/** @scrutinizer ignore-type */ $method, $uri, $server, $body, '1.1');
Loading history...
36
    }
37
}
38