CountryController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A show() 0 3 1
A destroy() 0 7 1
A store() 0 9 1
A update() 0 8 1
A index() 0 9 2
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\Country\CountryCreated;
9
use SaasReady\Events\Country\CountryDeleted;
10
use SaasReady\Events\Country\CountryUpdated;
11
use SaasReady\Http\Requests\Country\CountryDestroyRequest;
12
use SaasReady\Http\Requests\Country\CountryIndexRequest;
13
use SaasReady\Http\Requests\Country\CountryShowRequest;
14
use SaasReady\Http\Requests\Country\CountryStoreRequest;
15
use SaasReady\Http\Requests\Country\CountryUpdateRequest;
16
use SaasReady\Http\Responses\CountryResource;
17
use SaasReady\Models\Country;
0 ignored issues
show
Bug introduced by
The type SaasReady\Models\Country 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 CountryController extends Controller
20
{
21
    public function index(CountryIndexRequest $request): JsonResponse
22
    {
23
        $countries = Country::orderBy('name');
24
25
        return CountryResource::collection(
26
            $request->wantsPagination()
27
                ? $countries->paginate($request->getLimit())
28
                : $countries->get()
29
        )->toResponse($request);
30
    }
31
32
    public function show(CountryShowRequest $request, Country $country): JsonResponse
33
    {
34
        return (new CountryResource($country))->toResponse($request);
35
    }
36
37
    public function store(CountryStoreRequest $request): JsonResponse
38
    {
39
        $country = Country::create($request->validated());
40
41
        Event::dispatch(new CountryCreated($country));
42
43
        return new JsonResponse([
44
            'uuid' => $country->uuid,
45
        ], 201);
46
    }
47
48
    public function update(CountryUpdateRequest $request, Country $country): JsonResponse
49
    {
50
        $country->update($request->validated());
51
52
        Event::dispatch(new CountryUpdated($country));
53
54
        return new JsonResponse([
55
            'uuid' => $country->uuid,
56
        ]);
57
    }
58
59
    public function destroy(CountryDestroyRequest $request, Country $country): JsonResponse
60
    {
61
        $country->delete();
62
63
        Event::dispatch(new CountryDeleted($country));
64
65
        return new JsonResponse();
66
    }
67
}
68