Completed
Pull Request — development (#635)
by Ashutosh
09:42
created

CommentController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Http\Controllers\User;
4
5
use App\Comment;
6
use App\Http\Controllers\Controller;
7
use App\User;
8
use Bugsnag;
9
use Illuminate\Http\Request;
10
11
class CommentController extends Controller
12
{
13
    public function __construct()
14
    {
15
        $this->middleware('auth');
16
        $this->middleware('admin');
17
18
        $user = new User();
19
        $this->user = $user;
20
21
        $comment = new Comment();
22
        $this->comment = $comment;
23
    }
24
25
    /**
26
     * Display a listing of the resource.
27
     *
28
     * @return \Illuminate\Http\Response
29
     */
30
    public function index()
31
    {
32
        //
33
    }
34
35
    /**
36
     * Show the form for creating a new resource.
37
     *
38
     * @return \Illuminate\Http\Response
39
     */
40
    public function create()
41
    {
42
        //
43
    }
44
45
    /**
46
     * Store a newly created resource in storage.
47
     *
48
     * @param \Illuminate\Http\Request $request
49
     *
50
     * @return \Illuminate\Http\Response
51
     */
52
    public function store(Request $request)
53
    {
54
        try {
55
            $comments = $this->comment->fill($request->input())->save();
56
57
            return redirect()->back()->with('success', \Lang::get('message.saved-successfully'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...e.saved-successfully')) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
58
        } catch (Exception $ex) {
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\User\Exception was not found. Did you mean Exception? If so, make sure to prefix the type with \.
Loading history...
59
            app('log')->error($ex->getMessage());
60
            Bugsnag::notifyException($ex);
61
62
            return redirect()->back()->with('fails', $ex->getMessage());
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...ls', $ex->getMessage()) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
63
        }
64
    }
65
66
    /**
67
     * Update the specified resource in storage.
68
     *
69
     * @param \Illuminate\Http\Request $request
70
     * @param int                      $id
71
     *
72
     * @return \Illuminate\Http\Response
73
     */
74
    public function update(Request $request, $id)
75
    {
76
        try {
77
            $comment = $this->comment->where('id', $id)->update(['user_id'=> $request->input('user_id'),
78
            'updated_by_user_id'                                          => $request->input('updated_by_user_id'), 'description'=>$request->input('description'), ]);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 166 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
79
80
            return redirect()->back()->with('success', \Lang::get('message.updated-successfully'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...updated-successfully')) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
81
        } catch (Exception $ex) {
82
            app('log')->error($ex->getMessage());
83
            Bugsnag::notifyException($ex);
84
85
            return redirect()->back()->with('fails', $ex->getMessage());
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...ls', $ex->getMessage()) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
86
        }
87
    }
88
89
    /**
90
     * Remove the specified resource from storage.
91
     *
92
     * @param int $id
93
     *
94
     * @return \Illuminate\Http\Response
95
     */
96
    public function destroy($id)
97
    {
98
        try {
99
            $delComment = $this->comment->where('id', $id)->delete();
100
101
            return redirect()->back()->with('success', \Lang::get('message.deleted-successfully'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...deleted-successfully')) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
102
        } catch (Exception $e) {
103
            app('log')->error($ex->getMessage());
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ex seems to be never defined.
Loading history...
104
            Bugsnag::notifyException($ex);
105
106
            return redirect()->back()->with('fails', $ex->getMessage());
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back(...ls', $ex->getMessage()) also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
107
        }
108
    }
109
}
110