DeviceController   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 100
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 12
lcom 0
cbo 2

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A create() 0 4 1
A store() 0 4 1
A edit() 0 4 1
A update() 0 4 1
A destroy() 0 4 1
A index() 0 11 3
A show() 0 15 3
1
<?php
2
3
namespace App\Api\Controllers;
4
5
use App\Models\Device;
6
use App\Models\User;
7
use Illuminate\Http\Request;
8
9
class DeviceController extends Controller
10
{
11 1
    public function __construct()
12
    {
13 1
    }
14
15
    /**
16
     * Display a listing of all authorized devices
17
     *
18
     * @return \Illuminate\Http\Response
19
     */
20 1
    public function index(Request $request)
21
    {
22
        // fetch devices from the database
23 1
        $per_page = $request->per_page ?: 25;
24 1
        if ($request->user()->hasGlobalRead()) {
25 1
            $devices = Device::paginate($per_page);
26
        } else {
27
            $devices = User::find($request->user()->user_id)->devices()->paginate($per_page);
28
        }
29 1
        return $devices;
30
    }
31
32
    /**
33
     * Show the form for creating a new resource.
34
     *
35
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Response|null?

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...
36
     */
37
    public function create()
38
    {
39
        //
40
    }
41
42
    /**
43
     * Store a newly created resource in storage.
44
     *
45
     * @param  \Illuminate\Http\Request  $request
46
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Response|null?

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...
47
     */
48
    public function store(Request $request)
49
    {
50
        //
51
    }
52
53
    /**
54
     * Display the specified resource.
55
     *
56
     * @param  int  $id
57
     * @return \Illuminate\Http\Response
58
     */
59
    public function show(Request $request, $id)
60
    {
61
        if ($request->user()->hasGlobalRead()) {
62
            $device = Device::find($id);
63
        } else {
64
            $user = User::find($request->user()->user_id);
65
            $device = $user->devices()->find($id);
66
        }
67
        // morph the data as required
68
        if ($request->query('displayFormat') == 'link') {
69
            return '<a href="'.url('/devices/').$device->deviceId.'">'.$device->hostname.'</a>';
70
        }
71
72
        return $device;
73
    }
74
75
    /**
76
     * Show the form for editing the specified resource.
77
     *
78
     * @param  int  $id
79
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Response|null?

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...
80
     */
81
    public function edit($id)
82
    {
83
        //
84
    }
85
86
    /**
87
     * Update the specified resource in storage.
88
     *
89
     * @param  \Illuminate\Http\Request  $request
90
     * @param  int  $id
91
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Response|null?

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...
92
     */
93
    public function update(Request $request, $id)
94
    {
95
        //
96
    }
97
98
    /**
99
     * Remove the specified resource from storage.
100
     *
101
     * @param  int  $id
102
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Response|null?

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...
103
     */
104
    public function destroy($id)
105
    {
106
        //
107
    }
108
}
109