TranslationController::destroy()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 7
rs 10
c 0
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 Illuminate\Support\Facades\Event;
0 ignored issues
show
Bug introduced by
The type Illuminate\Support\Facades\Event 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...
8
use SaasReady\Events\Translation\TranslationCreated;
9
use SaasReady\Events\Translation\TranslationDeleted;
10
use SaasReady\Events\Translation\TranslationUpdated;
11
use SaasReady\Http\Requests\Translation\TranslationDestroyRequest;
12
use SaasReady\Http\Requests\Translation\TranslationIndexRequest;
13
use SaasReady\Http\Requests\Translation\TranslationShowRequest;
14
use SaasReady\Http\Requests\Translation\TranslationStoreRequest;
15
use SaasReady\Http\Requests\Translation\TranslationUpdateRequest;
16
use SaasReady\Http\Responses\TranslationResource;
17
use SaasReady\Models\Translation;
0 ignored issues
show
Bug introduced by
The type SaasReady\Models\Translation 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...
18
19
class TranslationController extends Controller
20
{
21
    public function index(TranslationIndexRequest $request): JsonResponse
22
    {
23
        $translations = Translation::query()
24
            ->when($request->getSearchKeyword(), fn ($q) => $q->filterByKeyword($request->getSearchKeyword()))
25
            ->paginate($request->getLimit());
26
27
        return TranslationResource::collection($translations)
28
            ->toResponse($request);
29
    }
30
31
    public function show(TranslationShowRequest $request, Translation $translation): JsonResponse
32
    {
33
        return (new TranslationResource($translation))->toResponse($request);
34
    }
35
36
    public function store(TranslationStoreRequest $request): JsonResponse
37
    {
38
        $translation = Translation::create($request->validated());
39
40
        Event::dispatch(new TranslationCreated($translation));
41
42
        return new JsonResponse([
43
            'uuid' => $translation->uuid,
44
        ], 201);
45
    }
46
47
    public function update(TranslationUpdateRequest $request, Translation $translation): JsonResponse
48
    {
49
        $translation->update($request->validated());
50
51
        Event::dispatch(new TranslationUpdated($translation));
52
53
        return new JsonResponse([
54
            'uuid' => $translation->uuid,
55
        ]);
56
    }
57
58
    public function destroy(TranslationDestroyRequest $request, Translation $translation): JsonResponse
59
    {
60
        $translation->delete();
61
62
        Event::dispatch(new TranslationDeleted($translation));
63
64
        return new JsonResponse();
65
    }
66
}
67