Passed
Pull Request — master (#264)
by John
04:37
created

MessageController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 25
rs 10
wmc 4
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Eloquent\MessageModel;
6
use Auth;
7
use Illuminate\Support\Facades\Redirect;
8
9
class MessageController extends Controller
10
{
11
    public function index()
12
    {
13
        $uid = Auth::user()->id;
14
        $messages = MessageModel::list($uid);
15
        return view('message.index', [
16
            'page_title'=>"Message",
17
            'site_title'=>config("app.name"),
18
            'navigation'=>"Home",
19
            'messages'=>$messages,
20
        ]);
21
    }
22
23
    public function detail($id)
24
    {
25
        $message = MessageModel::read($id);
26
        if(empty($message || $message->receiver != Auth::user()->id)){
0 ignored issues
show
Bug Best Practice introduced by
The expression $message of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
27
            return Redirect::route('message.index');
28
        }
29
        return view('message.detail', [
30
            'page_title'=>"Message",
31
            'site_title'=>config("app.name"),
32
            'navigation'=>"Home",
33
            'message' => $message
34
        ]);
35
    }
36
}
37