DocumentApiController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 26
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A index() 0 18 4
1
<?php
2
3
namespace Webfactor\Laravel\Backpack\Documents\Controllers;
4
5
use App\Http\Controllers\Controller;
6
use Illuminate\Http\Request;
7
use Spatie\Fractalistic\ArraySerializer;
8
9
class DocumentApiController
10
{
11
    /**
12
     * Get all documents and return the json response
13
     *
14
     * @return \Illuminate\Http\JsonResponse
0 ignored issues
show
Documentation introduced by
Should the return type not be \Spatie\Fractal\Fractal?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
15
     */
16
    public function index(Request $request)
17
    {
18
        if ($lang = $request->input('lang')) {
19
            \App::setLocale($lang);
20
        }
21
22
        $model = config('webfactor.documents.model_class');
23
24
        $documents = $model::all();
25
26
        if (!$documents || !$documents->count()) {
27
            abort(422);
28
        }
29
30
        $transformerClass = config('webfactor.documents.api.transformer');
31
32
        return fractal($documents, new $transformerClass(), new ArraySerializer());
33
    }
34
}
35