LanguageController::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\Language\LanguageCreated;
9
use SaasReady\Events\Language\LanguageDeleted;
10
use SaasReady\Events\Language\LanguageUpdated;
11
use SaasReady\Http\Requests\Language\LanguageDestroyRequest;
12
use SaasReady\Http\Requests\Language\LanguageIndexRequest;
13
use SaasReady\Http\Requests\Language\LanguageShowRequest;
14
use SaasReady\Http\Requests\Language\LanguageStoreRequest;
15
use SaasReady\Http\Requests\Language\LanguageUpdateRequest;
16
use SaasReady\Http\Responses\LanguageResource;
17
use SaasReady\Models\Language;
0 ignored issues
show
Bug introduced by
The type SaasReady\Models\Language 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 LanguageController extends Controller
20
{
21
    public function index(LanguageIndexRequest $request): JsonResponse
22
    {
23
        $languages = Language::orderBy('name')
24
            ->when($request->wantsActiveLanguages(), fn ($query) => $query->whereNotNull('activated_at'));
25
26
        return LanguageResource::collection(
27
            $request->wantsPagination()
28
                ? $languages->paginate($request->getLimit())
29
                : $languages->get()
30
        )->toResponse($request);
31
    }
32
33
    public function show(LanguageShowRequest $request, Language $language): JsonResponse
34
    {
35
        return (new LanguageResource($language))->toResponse($request);
36
    }
37
38
    public function store(LanguageStoreRequest $request): JsonResponse
39
    {
40
        $language = Language::create([
41
            ...$request->validated(),
42
            'activated_at' => $request->boolean('is_active') ? now() : null,
0 ignored issues
show
Bug introduced by
The function now was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
            'activated_at' => $request->boolean('is_active') ? /** @scrutinizer ignore-call */ now() : null,
Loading history...
43
        ]);
44
45
        Event::dispatch(new LanguageCreated($language));
46
47
        return new JsonResponse([
48
            'uuid' => $language->uuid,
49
        ], 201);
50
    }
51
52
    public function update(LanguageUpdateRequest $request, Language $language): JsonResponse
53
    {
54
        $language->update([
55
            ...$request->validated(),
56
            'activated_at' => $request->boolean('is_active') ? now() : null,
0 ignored issues
show
Bug introduced by
The function now was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
            'activated_at' => $request->boolean('is_active') ? /** @scrutinizer ignore-call */ now() : null,
Loading history...
57
        ]);
58
59
        Event::dispatch(new LanguageUpdated($language));
60
61
        return new JsonResponse([
62
            'uuid' => $language->uuid,
63
        ]);
64
    }
65
66
    public function destroy(LanguageDestroyRequest $request, Language $language): JsonResponse
67
    {
68
        $language->delete();
69
70
        Event::dispatch(new LanguageDeleted($language));
71
72
        return new JsonResponse();
73
    }
74
}
75