| Conditions | 3 |
| Paths | 3 |
| Total Lines | 27 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 3 |
| 1 | <?php |
||
| 17 | 10 | public function __invoke( |
|
| 18 | ServerRequestInterface $request |
||
| 19 | ) { |
||
| 20 | 10 | $attrs = $request->getAttributes(); |
|
|
|
|||
| 21 | 10 | $body = $request->getParsedBody(); |
|
| 22 | 10 | $cookies = $request->getCookieParams(); |
|
| 23 | 10 | $query = $request->getQueryParams(); |
|
| 24 | 10 | $uploads = $request->getUploadedFiles(); |
|
| 25 | |||
| 26 | 10 | if (empty($body)) { |
|
| 27 | 8 | $body = []; |
|
| 28 | 3 | } elseif (is_object($body)) { |
|
| 29 | // Because the parsed body may also be represented as an object, |
||
| 30 | // additional parsing is required. This is a bit dirty but works |
||
| 31 | // very well for anonymous objects. |
||
| 32 | 1 | $body = json_decode(json_encode($body), true); |
|
| 33 | } |
||
| 34 | |||
| 35 | // Order matters here! Important values go last! |
||
| 36 | 10 | return array_replace( |
|
| 37 | $query, |
||
| 38 | $body, |
||
| 39 | $uploads, |
||
| 40 | $cookies, |
||
| 41 | $attrs |
||
| 42 | ); |
||
| 43 | } |
||
| 44 | } |
||
| 45 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.