EventController::show()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 7
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace SaasReady\Http\Controllers;
4
5
use Illuminate\Http\JsonResponse;
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\JsonResponse 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...
6
use Illuminate\Routing\Controller;
0 ignored issues
show
Bug introduced by
The type Illuminate\Routing\Controller 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...
7
use SaasReady\Http\Requests\Event\EventIndexRequest;
8
use SaasReady\Http\Requests\Event\EventShowRequest;
9
use SaasReady\Http\Responses\EventResource;
10
use SaasReady\Models\Event;
11
12
class EventController extends Controller
13
{
14
    public function index(EventIndexRequest $request): JsonResponse
15
    {
16
        $countries = Event::orderBy('created_at', 'DESC')
17
            ->where([
18
                'model_id' => $request->getRelatedModel()->getKey(),
19
                'model_type' => $request->getRelatedModel()->getMorphClass(),
20
            ])
21
            ->when($request->getUserId(), fn ($builder) => $builder->whereUserId($request->getUserId()))
22
            ->when($request->input('load_related_model'), fn ($builder) => $builder->with(['model']));
23
24
        return EventResource::collection($countries->paginate($request->getLimit()))
25
            ->toResponse($request);
26
    }
27
28
    public function show(EventShowRequest $request, Event $country): JsonResponse
29
    {
30
        if ($request->input('load_related_model')) {
31
            $country->load(['model']);
32
        }
33
34
        return (new EventResource($country))->toResponse($request);
35
    }
36
}
37