DirectRequestController::__invoke()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 23
ccs 16
cts 16
cp 1
rs 9.7998
cc 4
nc 3
nop 1
crap 4
1
<?php
2
3
namespace NovaNavigaAdPreview\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Facades\Response;
7
use Illuminate\Support\Str;
8
use NavigaAdClient\NavigaAd;
9
use NavigaAdClient\Responses\PaginatedResponse;
0 ignored issues
show
Bug introduced by
The type NavigaAdClient\Responses\PaginatedResponse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
class DirectRequestController extends Controller
12
{
13 1
    public function __invoke(Request $request)
14
    {
15 1
        $request->validate([
16 1
            'endpoint' => ['required', 'string'],
17 1
            'query'    => ['nullable', 'string'],
18 1
        ]);
19
20 1
        $endpoint  = $request->input('endpoint');
21 1
        $query     = array_filter(array_map('trim', explode(PHP_EOL, $request->input('query', ''))));
22 1
        $queryData = [];
23 1
        foreach ($query as $line) {
24 1
            $key   = Str::before($line, ':');
25 1
            $value = Str::after($line, ':');
26 1
            if ($key && $value) {
27 1
                $queryData[$key] = $value;
28
            }
29
        }
30
31
        /** @var PaginatedResponse $response */
32 1
        $response = NavigaAd::pendingRequest()->get($endpoint, $queryData);
33
34 1
        return Response::json([
35 1
            'data' => $response->json(),
36 1
        ]);
37
    }
38
}
39