PortController::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Api\Controllers;
4
5
use App\Api\Transformers\PortTransformer;
6
use App\Models\Port;
7
use App\Models\User;
8
use Auth;
9
use Dingo\Api\Routing\Helpers;
10
use Illuminate\Http\Request;
11
12
class PortController extends Controller
13
{
14
    use Helpers;
15
16
    public function __construct()
17
    {
18
    }
19
20
    /**
21
     * Display a listing of the resource.
22
     *
23
     * @return \Illuminate\Http\Response
24
     */
25
    public function index(Request $request)
26
    {
27
        if (Auth::user()->hasGlobalRead()) {
28
            $ports = Port::all();
29
        } else {
30
            $ports = Auth::user()->ports()->get();
31
        }
32
33
        return $this->response->collection($ports, new PortTransformer);
34
    }
35
36
    /**
37
     * Show the form for creating a new resource.
38
     *
39
     * @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...
40
     */
41
    public function create()
42
    {
43
        //
44
    }
45
46
    /**
47
     * Store a newly created resource in storage.
48
     *
49
     * @param  \Illuminate\Http\Request  $request
50
     * @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...
51
     */
52
    public function store(Request $request)
53
    {
54
        //
55
    }
56
57
    /**
58
     * Display the specified resource.
59
     *
60
     * @param  int  $id
61
     * @return \Illuminate\Http\Response
62
     */
63
    public function show(Request $request, $id)
64
    {
65
        if ($request->user()->hasGlobalRead()) {
66
            return Port::find($id);
67
        } else {
68
            $user = User::find($request->user()->user_id);
69
            return $user->ports()->find($id);
70
        }
71
    }
72
73
    /**
74
     * Show the form for editing the specified resource.
75
     *
76
     * @param  int  $id
77
     * @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...
78
     */
79
    public function edit($id)
80
    {
81
        //
82
    }
83
84
    /**
85
     * Update the specified resource in storage.
86
     *
87
     * @param  \Illuminate\Http\Request  $request
88
     * @param  int  $id
89
     * @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...
90
     */
91
    public function update(Request $request, $id)
92
    {
93
        //
94
    }
95
96
    /**
97
     * Remove the specified resource from storage.
98
     *
99
     * @param  int  $id
100
     * @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...
101
     */
102
    public function destroy($id)
103
    {
104
        //
105
    }
106
}
107