Passed
Push — master ( af710d...2c0b17 )
by Dan Michael O.
08:29
created

PublicApiController::things()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 40
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 26
nc 2
nop 1
dl 0
loc 40
rs 9.504
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\Request 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
7
class PublicApiController extends Controller
8
{
9
10
    public function things(Request $request)
11
    {
12
        $libraryId = $request->input('library');
13
14
        $things = Thing::with('items');
15
        if ($request->has('library')) {
16
            $things->whereHas('');
17
        }
18
19
20
        $things = Thing::with('items', 'settings', 'items.loans')
21
            ->orderBy('name')
22
            ->get();
23
24
        $things = $things->map(function ($thing) use ($libraryId) {
25
            $all = $thing->items->whereNotIn('barcode', [null]);
26
            $avail = $all->filter(function (Item $item) {
27
                return is_null($item->activeLoan);
28
            });
29
            $mine = $all->where('library_id', $libraryId);
30
            $avail_mine = $avail->where('library_id', $libraryId);
31
32
            return [
33
                'type' => 'thing',
34
                'id' => $thing->id,
35
                'name' => $thing->name,
36
                'library_settings' => $thing->library_settings,
37
                'properties' => $thing->properties,
38
                'loan_time' => $thing->loan_time,
39
40
                'items_total' => $all->count(),
41
                'items_mine' => $mine->count(),
42
43
                'avail_total' => $avail->count(),
44
                'avail_mine' => $avail_mine->count(),
45
            ];
46
        });
47
48
        return response()->view('things.index', [
0 ignored issues
show
Bug introduced by
The function response 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

48
        return /** @scrutinizer ignore-call */ response()->view('things.index', [
Loading history...
49
            'things' => $things,
50
        ]);
51
    }
52
}
53