Completed
Push — master ( 9fe7e8...7331b7 )
by Aurimas
12:47
created

QueryParamParser   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2
Metric Value
wmc 1
lcom 0
cbo 2
dl 0
loc 13
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 6 1
1
<?php
2
3
namespace Thruster\Component\Http\Parser;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
7
/**
8
 * Class QueryParamParser
9
 *
10
 * @package Thruster\Component\Http\Parser
11
 * @author  Aurimas Niekis <[email protected]>
12
 */
13
class QueryParamParser implements ParserInterface
14
{
15
    /**
16
     * @inheritDoc
17
     */
18
    public function parse(ServerRequestInterface $request) : ServerRequestInterface
19
    {
20
        parse_str($request->getUri()->getQuery(), $queryParams);
21
22
        return $request->withQueryParams($queryParams);
0 ignored issues
show
Bug introduced by
It seems like $queryParams can also be of type null; however, Psr\Http\Message\ServerR...face::withQueryParams() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
23
    }
24
25
}
26