Completed
Pull Request — master (#107)
by Glenn
23:25 queued 15:40
created

DepartmentsController::store()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 20
rs 9.4285
cc 1
eloc 13
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use App\Http\Requests;
7
use App\Departments;
8
use App\DepartmentMembers;
9
use Mail;
10
use App\User;
11
use App\Http\Controllers\Controller;
12
13
class DepartmentsController extends Controller
14
{
15
    /**
16
     * DepartmentsController Constructor.
17
     */
18
    public function __construct()
19
    {
20
        $this->middleware('auth');
21
    }
22
23
    /**
24
     * Get the departments index.
25
     *
26
     * @return view
27
     */ 
28
    public function index()
29
    {
30
        $departments = Departments::orderBy('department_name', 'asc')->with('managers')->paginate(10);
31
        return view('departments/list', ['departments' => $departments]);
32
    }
33
34
    /**
35
     * This is nothing for in the controller.
36
     * If you want to test this. You should create a phpunit function for the relation.$_COOKIE
37
     * 
38
     * TODO: Create phpunit testing function.
39
     */
40
    public function relationtest()
41
    {
42
        $departments = DepartmentMembers::All();
43
        return $departments;
44
    }    
45
46
    public function create()
47
    {
48
        $managers = User::all();
49
        return view('departments/create', ['managers' => $managers]);
50
    }
51
52
    /**
53
     * Store a newly created resource in storage.
54
     *
55
     * @param  Requests\DepartmentsValidator|Request $request
56
     * @return \Illuminate\Http\Response
57
     */
58
    public function store(Requests\DepartmentsValidator $request)
59
    {
60
        // TODO: Check for mass assign - SQL queries.
61
        
62
        $departments = new Departments;
63
        $departments->department_name = $request->get('department_name');
64
        $departments->department_manager = $request->get('department_manager');
65
        $departments->department_description = $request->get('department_description');
66
        $departments->save();
67
68
        $department_id = $departments->id;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Departments>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
69
70
        $manager = new DepartmentMembers;
71
        $manager->departmentid = $department_id;
72
        $manager->userid = $request->get('department_manager');
73
        $manager->save();
74
75
         \Session::flash('message', "New department has been saved");
76
        return redirect('staff/departments');
77
    }
78
79
    /**
80
     * Display the specified resource.
81
     *
82
     * @param  int  $id
83
     * @return \Illuminate\Http\Response
84
     */
85
    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...
86
    {
87
        //
88
    }
89
90
    /**
91
     * Show the form for editing the specified resource.
92
     *
93
     * @param  int  $id
94
     * @return \Illuminate\Http\Response
95
     */
96
    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...
97
    {
98
        return view('departments/edit');
99
    }
100
101
    /**
102
     * Update the specified resource in storage.
103
     *
104
     * @param  \Illuminate\Http\Request  $request
105
     * @param  int  $id
106
     * @return \Illuminate\Http\Response
107
     */
108
    public function update(Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $request 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...
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...
109
    {
110
        //
111
    }
112
113
    /**
114
     * Remove the specified resource from storage.
115
     *
116
     * @param  int  $id
117
     * @return \Illuminate\Http\Response
118
     */
119
    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...
120
    {
121
        //
122
    }
123
}
124