ParseQueryParamModifier::modify()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Thruster\Component\HttpModifiers;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
use Thruster\Component\HttpModifier\ServerRequestModifierInterface;
7
8
/**
9
 * Class ParseQueryParamModifier
10
 *
11
 * @package Thruster\Component\HttpModifiers\ResponseModifier
12
 * @author  Aurimas Niekis <[email protected]>
13
 */
14
class ParseQueryParamModifier implements ServerRequestModifierInterface
15
{
16 1
    public function modify(ServerRequestInterface $request) : ServerRequestInterface
17
    {
18 1
        parse_str($request->getUri()->getQuery(), $queryParams);
19
20 1
        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...
21
    }
22
23
}
24