EmployeesController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A destroy() 0 11 2
A index() 0 7 1
A store() 0 9 1
1
<?php
2
3
namespace plunner\Http\Controllers\Companies\Groups;
4
5
use Illuminate\Support\Facades\Response;
6
use plunner\Employee;
7
use plunner\Group;
8
use plunner\Http\Controllers\Controller;
9
use plunner\Http\Requests\Companies\Groups\EmployeeRequest;
10
11
/**
12
 * Class EmployeesController
13
 * @package plunner\Http\Controllers\Companies\Groups
14
 * @author Claudio Cardinale <[email protected]>
15
 * @copyright 2015 Claudio Cardinale
16
 * @version 1.0.0
17
 */
18
class EmployeesController extends Controller
19
{
20 24
    public function __construct()
21
    {
22 24
        config(['auth.model' => \plunner\Company::class]);
23 24
        config(['jwt.user' => \plunner\Company::class]);
24 24
        $this->middleware('jwt.authandrefresh:mode-cn');
25 24
    }
26
27
28
    /**
29
     * Display a listing of the resource.
30
     *
31
     * @param  int $groupId
32
     * @return \Illuminate\Http\Response
33
     */
34 3
    public function index($groupId)
35
    {
36
        //
37 3
        $group = Group::findOrFail($groupId);
38 3
        $this->authorize($group);
39 3
        return $group->employees;
40
    }
41
42
    /**
43
     * Store a newly created resource in storage.
44
     *
45
     * @param  EmployeeRequest $request
46
     * @param  int $groupId
47
     * @return \Illuminate\Http\Response
48
     */
49 6
    public function store(EmployeeRequest $request, $groupId)
50
    {
51
        //
52 6
        $group = Group::findOrFail($groupId);
53 6
        $this->authorize($group);
54 3
        $id = $request->all()['id'];
55 3
        $group->employees()->attach($id);
56 3
        return $group->employees;
57
    }
58
59
    /**
60
     * Remove the specified resource from storage.
61
     *
62
     * @param  int $groupId
63
     * @param  int $employeeId
64
     * @return \Illuminate\Http\Response
65
     */
66 12
    public function destroy($groupId, $employeeId)
67
    {
68
        //
69 12
        $employee = Employee::findOrFail($employeeId);
70 12
        $this->authorize($employee);
71 6
        $group = Group::findOrFail($groupId);
72 6
        if (!$employee->belongsToGroup($group))
73 6
            return Response::json(['error' => 'employId <> groupId'], 404);
74 3
        $employee->groups()->detach($groupId);
75 3
        return $group->employees;
76
    }
77
}
78