Completed
Pull Request — master (#2)
by claudio
03:56
created

GroupsController::show()   A

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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace plunner\Http\Controllers\Employees;
4
5
use Illuminate\Http\Request;
6
7
use plunner\Group;
8
use plunner\Employee;
9
use plunner\Http\Requests;
10
use plunner\Http\Controllers\Controller;
11
12
class GroupsController extends Controller
13
{
14
    private $responder;
15
16
    public function __create(ReponseCreator $responder)
17
    {
18
        $this->responder = $responder;
19
    }
20
21
    /**
22
     * Display a listing of the resource.
23
     *
24
     * @return \Illuminate\Http\Response
25
     */
26
    public function index()
27
    {
28
        //
29
    }
30
31
    /**
32
     * Show the form for creating a new resource.
33
     *
34
     * @return \Illuminate\Http\Response
35
     */
36
    public function create()
37
    {
38
        //
39
    }
40
41
    /**
42
     * Store a newly created resource in storage.
43
     *
44
     * @param  \Illuminate\Http\Request $request
45
     * @return \Illuminate\Http\Response
46
     */
47
    public function store(Request $request)
48
    {
49
        $this->validateGroupUpdates($request);
50
        $input = $request->all();
51
52
        $g = Group::create([
53
            'name' => $input['group_name'],
54
            'description' => isset($input['description']) ? $input['description'] : ''
55
        ]);
56
        $employees = Employee::whereIn('name', $input['employees'])->get();
0 ignored issues
show
Documentation introduced by
The method whereIn does not exist on object<plunner\Employee>? Since you implemented __callStatic, maybe consider adding a @method annotation.
Loading history...
57
58
        $g->addEmployees($employees);
59
60
        return $this->respondOK();
61
    }
62
63
    /**
64
     * Display the specified resource.
65
     *
66
     * @param  int $id
67
     * @return \Illuminate\Http\Response
68
     */
69
    public function show($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
70
    {
71
        //
72
    }
73
74
    /**
75
     * Show the form for editing the specified resource.
76
     *
77
     * @param  int $id
78
     * @return \Illuminate\Http\Response
79
     */
80
    public function edit($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
81
    {
82
        //
83
    }
84
85
    /**
86
     * Update the specified resource in storage.
87
     *
88
     * @param  \Illuminate\Http\Request $request
89
     * @param  int $id
90
     * @return \Illuminate\Http\Response
91
     */
92
    public function update(Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
93
    {
94
        $this->validateGroupUpdates($request);
95
        $input = $request->all();
96
97
        $employees = Employee::whereIn('name', $input['employees'])->get();
0 ignored issues
show
Documentation introduced by
The method whereIn does not exist on object<plunner\Employee>? Since you implemented __callStatic, maybe consider adding a @method annotation.
Loading history...
98
99
        try {
100
            $group = Group::findOrFail($input['group_name']);
0 ignored issues
show
Documentation introduced by
The method findOrFail does not exist on object<plunner\Group>? Since you implemented __callStatic, maybe consider adding a @method annotation.
Loading history...
101
        } catch (ModelNotFoundException $e) {
0 ignored issues
show
Bug introduced by
The class plunner\Http\Controllers...\ModelNotFoundException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
102
            return $this->responder->respond(
103
                [
104
                    'message' => 'Group not found',
105
                    'group_name' => $input['group_name']
106
                ],
107
                404
108
            );
109
        }
110
        $group->addEmployees($employees);
111
112
        return $this->respondOK();
113
    }
114
115
    private function validateGroupUpdates($request)
116
    {
117
        $this->validate($request, [
118
            'group_name' => 'required|max:255',
119
            'employees' => 'required|array',
120
        ]);
121
    }
122
123
    private function respondOK()
124
    {
125
        return $this->responder->respond([], 200);
126
    }
127
128
    /**
129
     * Remove the specified resource from storage.
130
     *
131
     * @param  int $id
132
     * @return \Illuminate\Http\Response
133
     */
134
    public function destroy($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
135
    {
136
        //
137
    }
138
}
139