Completed
Push — master ( c6be7b...ac3a6a )
by claudio
03:59
created

EmployeesController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 68
ccs 23
cts 23
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A index() 0 7 1
A store() 0 9 1
A destroy() 0 11 2
1
<?php
2
3
namespace plunner\Http\Controllers\Companies\Groups;
4
5
use Illuminate\Support\Facades\Response;
6
use plunner\Group;
7
use plunner\Employee;
8
use plunner\Http\Controllers\Controller;
9
use plunner\Http\Requests\Companies\Groups\EmployeeRequest;
10
11
12
class EmployeesController extends Controller
13
{
14
    /**
15
     * @var \plunner\Company
16
     */
17
    private $user;
0 ignored issues
show
Unused Code introduced by
The property $user is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
18
19
    /**
20
     * ExampleController constructor.
21
     */
22 15
    public function __construct()
23
    {
24 15
        config(['auth.model' => \plunner\Company::class]);
25 15
        config(['jwt.user' => \plunner\Company::class]);
26 15
        $this->middleware('jwt.authandrefresh:mode-cn');
27 15
    }
28
29
30
    /**
31
     * Display a listing of the resource.
32
     *
33
     * @param  int  $groupId
34
     * @return \Illuminate\Http\Response
35
     */
36 2
    public function index($groupId)
37
    {
38
        //
39 2
        $group = Group::findOrFail($groupId);
40 2
        $this->authorize($group);
41 2
        return $group->employees;
42
    }
43
44
    /**
45
     * Store a newly created resource in storage.
46
     *
47
     * @param  EmployeeRequest  $request
48
     * @param  int  $groupId
49
     * @return \Illuminate\Http\Response
50
     */
51 4
    public function store(EmployeeRequest $request, $groupId)
52
    {
53
        //
54 4
        $group = Group::findOrFail($groupId);
55 4
        $this->authorize($group);
56 2
        $id = $request->all()['id'];
57 2
        $group->employees()->attach($id);
58 2
        return $group->employees;
59
    }
60
61
    /**
62
     * Remove the specified resource from storage.
63
     *
64
     * @param  int  $groupId
65
     * @param  int  $employeeId
66
     * @return \Illuminate\Http\Response
67
     */
68 7
    public function destroy($groupId, $employeeId)
69
    {
70
        //
71 7
        $employee = Employee::findOrFail($employeeId);
72 7
        $this->authorize($employee);
73 3
        $group = Group::findOrFail($groupId);
74 3
        if(!$employee->belongsToGroup($group))
75 3
            return Response::json(['error' => 'employId <> groupId'],404);
76 2
        $employee->groups()->detach($groupId);
77 2
        return $group->employees;
78
    }
79
}
80