ListRequestController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 21
c 1
b 0
f 0
dl 0
loc 31
ccs 22
cts 22
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 29 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 ListRequestController extends Controller
12
{
13 1
    public function __invoke(Request $request)
14
    {
15 1
        $request->validate([
16 1
            'page'     => ['nullable', 'integer', 'min:1'],
17 1
            'endpoint' => ['required', 'string'],
18 1
            'query'    => ['nullable', 'string'],
19 1
        ]);
20
21 1
        $endpoint  = $request->input('endpoint');
22 1
        $query     = array_filter(array_map('trim', explode(PHP_EOL, $request->input('query', ''))));
23 1
        $queryData = [];
24 1
        foreach ($query as $line) {
25 1
            $key   = Str::before($line, ':');
26 1
            $value = Str::after($line, ':');
27 1
            if ($key && $value) {
28 1
                $queryData[$key] = $value;
29
            }
30
        }
31
32
        /** @var PaginatedResponse $response */
33 1
        $response = NavigaAd::paginatedRequest($endpoint, 2)->setCurrentPage($request->input('page', 1))->retrieve($queryData);
34
35 1
        return Response::json([
36 1
            'data' => $response->entities(),
37 1
            'meta' => [
38 1
                'currentPage'   => $response->currentPage(),
39 1
                'totalPages'    => $response->totalPages(),
40 1
                'countEntities' => $response->countEntities(),
41 1
                'totalEntities' => $response->totalEntities(),
42 1
            ],
43 1
        ]);
44
    }
45
}
46