ConversationsCell::sidebar()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 49
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 9.2258
c 0
b 0
f 0
cc 2
eloc 32
nc 2
nop 0
1
<?php
2
namespace App\View\Cell;
3
4
use Cake\View\Cell;
5
6
class ConversationsCell extends Cell
7
{
8
    /**
9
     * Display the sidebar.
10
     *
11
     * @return void
12
     */
13
    public function sidebar()
14
    {
15
        $this->loadModel('ConversationsUsers');
16
        $this->loadModel('Conversations');
17
18
        $id = isset($this->request->id) ? $this->request->id : null;
19
20
        $participants = $this->ConversationsUsers
0 ignored issues
show
Bug introduced by
The property ConversationsUsers does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
21
            ->find()
22
            ->contain([
23
                'Users' => function ($q) {
24
                    return $q->find('full');
25
                },
26
                'Users.Groups' => function ($q) {
27
                    return $q->select(['id', 'name', 'css', 'is_staff', 'is_member']);
28
                }
29
            ])
30
            ->where([
31
                'ConversationsUsers.conversation_id' => $id
32
            ])
33
            ->toArray();
34
35
        $conversation = $this->Conversations
0 ignored issues
show
Bug introduced by
The property Conversations does not seem to exist. Did you mean ConversationsUsers?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
36
            ->find()
37
            ->contain([
38
                'LastMessageUser'
39
            ])
40
            ->where([
41
                'Conversations.id' => $id
42
            ])
43
            ->first();
44
45
        //Current user.
46
        $this->loadModel('Users');
47
        $currentUser = $this->Users
0 ignored issues
show
Bug introduced by
The property Users does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
48
            ->find()
49
            ->contain([
50
                'Groups' => function ($q) {
51
                    return $q->select(['id', 'is_staff']);
52
                }
53
            ])
54
            ->where([
55
                'Users.id' => $this->request->session()->read('Auth.User.id')
56
            ])
57
            ->select(['id', 'group_id'])
58
            ->first();
59
60
        $this->set(compact('conversation', 'participants', 'currentUser'));
61
    }
62
}
63