ReleaseNoteController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 44
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A store() 0 9 1
A destroy() 0 7 1
A show() 0 3 1
A update() 0 8 1
A index() 0 6 1
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\ReleaseNote\ReleaseNoteCreated;
9
use SaasReady\Events\ReleaseNote\ReleaseNoteDeleted;
10
use SaasReady\Events\ReleaseNote\ReleaseNoteUpdated;
11
use SaasReady\Http\Requests\ReleaseNote\ReleaseNoteDestroyRequest;
12
use SaasReady\Http\Requests\ReleaseNote\ReleaseNoteIndexRequest;
13
use SaasReady\Http\Requests\ReleaseNote\ReleaseNoteShowRequest;
14
use SaasReady\Http\Requests\ReleaseNote\ReleaseNoteStoreRequest;
15
use SaasReady\Http\Requests\ReleaseNote\ReleaseNoteUpdateRequest;
16
use SaasReady\Http\Responses\ReleaseNoteResource;
17
use SaasReady\Models\ReleaseNote;
18
19
class ReleaseNoteController extends Controller
20
{
21
    public function index(ReleaseNoteIndexRequest $request): JsonResponse
22
    {
23
        $releaseNotes = ReleaseNote::latest();
24
25
        return ReleaseNoteResource::collection($releaseNotes->paginate($request->getLimit()))
26
            ->toResponse($request);
27
    }
28
29
    public function show(ReleaseNoteShowRequest $request, ReleaseNote $releaseNote): JsonResponse
30
    {
31
        return (new ReleaseNoteResource($releaseNote))->toResponse($request);
32
    }
33
34
    public function store(ReleaseNoteStoreRequest $request): JsonResponse
35
    {
36
        $releaseNote = ReleaseNote::create($request->validated());
37
38
        Event::dispatch(new ReleaseNoteCreated($releaseNote));
39
40
        return new JsonResponse([
41
            'uuid' => $releaseNote->uuid,
42
        ], 201);
43
    }
44
45
    public function update(ReleaseNoteUpdateRequest $request, ReleaseNote $releaseNote): JsonResponse
46
    {
47
        $releaseNote->update($request->validated());
48
49
        Event::dispatch(new ReleaseNoteUpdated($releaseNote));
50
51
        return new JsonResponse([
52
            'uuid' => $releaseNote->uuid,
53
        ]);
54
    }
55
56
    public function destroy(ReleaseNoteDestroyRequest $request, ReleaseNote $releaseNote): JsonResponse
57
    {
58
        $releaseNote->delete();
59
60
        Event::dispatch(new ReleaseNoteDeleted($releaseNote));
61
62
        return new JsonResponse();
63
    }
64
}
65