Completed
Push — master ( 885948...db2a72 )
by Brandon
02:49
created

UserController::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
ccs 0
cts 2
cp 0
rs 9.4285
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Validator;
6
use Illuminate\Http\Request;
7
use App\Http\Controllers\Controller;
8
use App\DataTables\UsersDataTable;
9
use Illuminate\Support\Facades\Auth;
10
use Illuminate\Validation\Rule;
11
12
class UserController extends Controller
13
{
14
    /**
15
     * Create a new controller instance.
16
     *
17
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
18
     */
19
    public function __construct()
20
    {
21
        $this->middleware('auth');
22
        // TODO: Setup logging
23
        // $this->middleware('log')->only('index');
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
24
    }
25
26
    /* Auto route definitions for resource routes:
27
     * TYPE       URL                   METHOD   VIEW
28
     * ---------- --------------------- -------- -------------
29
     * GET	      /users                index    users.index
30
     * GET	      /users/create	        create   users.create
31
     * POST	      /users	            store	 users.store
32
     * GET	      /users/{id}           show     users.show
33
     * GET	      /users/{id}/edit      edit     users.edit
34
     * PUT/PATCH  /users/{id}           update   users.update
35
     * DELETE	  /users/{id}           destroy  users.destroy
36
     */
37
38
    /**
39
     * Display index page and process dataTable ajax request.
40
     *
41
     * @param \App\DataTables\UsersDataTable $dataTable
42
     * @return \Illuminate\Http\JsonResponse|\Illuminate\View\View
43
     */
44
    public function index(UsersDataTable $dataTable)
45
    {
46
        return $dataTable->render('users.index');
47
    }
48
49
    /**
50
     * Show create user page.
51
     *
52
     * @return \BladeView|bool|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
53
     */
54
    public function create()
55
    {
56
        return view('users.create');
57
    }
58
59
    /**
60
     * Store a new user.
61
     *
62
     * @param  Request  $request
63
     * @return Response
64
     */
65
    public function store(Request $request)
66
    {
67
        $validator = Validator::make($request->all(), [
68
            'name' => 'required|max:255',
69
            'email' => 'required|email|unique:users,email|max:255',
70
            'role' => 'required|integer',
71
        ]);
72
73
        if ($validator->fails()) {
74
            return redirect('users/create')->withErrors($validator)->withInput();
75
        }
76
77
        //Auth::login($this->create($request->all()));
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
78
79
        return redirect('users');
80
    }
81
82
    /**
83
     * Update the given user.
84
     *
85
     * @param  Request  $request
86
     * @param  string  $id
87
     * @return Response
88
     */
89
    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...
90
    {
91
        // TODO: Since HTML forms can't make PUT, PATCH, or DELETE requests, you will need
92
        // to add a hidden  _method field to spoof these HTTP verbs. The
93
        // method_field helper can create this field for you:
94
        // {{ method_field('PUT') }}
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
95
96
        // TODO: Use users model method to update record.
97
        return redirect('users');
98
    }
99
}
100