| Conditions | 3 |
| Paths | 3 |
| Total Lines | 20 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 12 |
| Changes | 0 | ||
| 1 | <?php |
||
| 32 | private function callApi(string $endpoint, Request $request) |
||
| 33 | { |
||
| 34 | $requestMethod = strtolower($request->getMethod()); |
||
| 35 | $arguments = $request->all(); |
||
| 36 | $url = "/api/{$endpoint}"; |
||
| 37 | |||
| 38 | $methodSupportsArguments = \in_array($requestMethod, ['post', 'put', 'patch']); |
||
| 39 | $callArguments = [$url]; |
||
| 40 | |||
| 41 | if (true === $methodSupportsArguments) { |
||
| 42 | $callArguments = [$url, $arguments]; |
||
| 43 | |||
| 44 | return $this->{$requestMethod}(...$callArguments); |
||
| 45 | } |
||
| 46 | |||
| 47 | if (false === empty($arguments)) { |
||
| 48 | $callArguments = [$url . '?' . http_build_query($arguments)]; |
||
| 49 | } |
||
| 50 | |||
| 51 | return $this->{$requestMethod}(...$callArguments); |
||
| 52 | } |
||
| 54 |