CurrencyController::destroy()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
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 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\Currency\CurrencyCreated;
9
use SaasReady\Events\Currency\CurrencyDeleted;
10
use SaasReady\Events\Currency\CurrencyUpdated;
11
use SaasReady\Http\Requests\Currency\CurrencyDestroyRequest;
12
use SaasReady\Http\Requests\Currency\CurrencyIndexRequest;
13
use SaasReady\Http\Requests\Currency\CurrencyShowRequest;
14
use SaasReady\Http\Requests\Currency\CurrencyStoreRequest;
15
use SaasReady\Http\Requests\Currency\CurrencyUpdateRequest;
16
use SaasReady\Http\Responses\CurrencyResource;
17
use SaasReady\Models\Currency;
0 ignored issues
show
Bug introduced by
The type SaasReady\Models\Currency 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 CurrencyController extends Controller
20
{
21
    public function index(CurrencyIndexRequest $request): JsonResponse
22
    {
23
        $currencies = Currency::orderBy('name')
24
            ->when($request->wantsActivated(), fn ($q) => $q->whereNotNull('activated_at'));
25
26
        return CurrencyResource::collection(
27
            $request->wantsPagination()
28
                ? $currencies->paginate($request->getLimit())
29
                : $currencies->get()
30
        )->toResponse($request);
31
    }
32
33
    public function show(CurrencyShowRequest $request, Currency $currency): JsonResponse
34
    {
35
        return (new CurrencyResource($currency))->toResponse($request);
36
    }
37
38
    public function store(CurrencyStoreRequest $request): JsonResponse
39
    {
40
        $currency = Currency::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 CurrencyCreated($currency));
46
47
        return new JsonResponse([
48
            'uuid' => $currency->uuid,
49
        ], 201);
50
    }
51
52
    public function update(CurrencyUpdateRequest $request, Currency $currency): JsonResponse
53
    {
54
        $currency->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 CurrencyUpdated($currency));
60
61
        return new JsonResponse([
62
            'uuid' => $currency->uuid,
63
        ]);
64
    }
65
66
    public function destroy(CurrencyDestroyRequest $request, Currency $currency): JsonResponse
67
    {
68
        $currency->delete();
69
70
        Event::dispatch(new CurrencyDeleted($currency));
71
72
        return new JsonResponse();
73
    }
74
}
75