ConversationsController   F
last analyzed

Complexity

Total Complexity 94

Size/Duplication

Total Lines 1176
Duplicated Lines 13.1 %

Coupling/Cohesion

Components 1
Dependencies 16

Importance

Changes 0
Metric Value
wmc 94
lcom 1
cbo 16
dl 154
loc 1176
rs 0.6314
c 0
b 0
f 0

18 Methods

Rating   Name   Duplication   Size   Complexity  
C create() 0 141 11
B view() 0 82 2
B inviteMember() 0 24 3
A quote() 0 55 3
B messageEdit() 0 53 6
C kick() 0 82 7
A initialize() 0 6 1
B beforeFilter() 0 12 5
B index() 0 32 1
A go() 48 48 3
B getEditMessage() 8 56 5
C action() 55 110 12
C reply() 5 101 11
B edit() 14 49 6
C invite() 5 95 11
A leave() 9 47 3
A search() 10 50 3
A maintenance() 0 3 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like ConversationsController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ConversationsController, and based on these observations, apply Extract Interface, too.

1
<?php
2
namespace App\Controller;
3
4
use App\Event\Notifications;
5
use Cake\Core\Configure;
6
use Cake\Database\Expression\QueryExpression;
7
use Cake\Event\Event;
8
use Cake\I18n\Time;
9
use Cake\Network\Exception\NotFoundException;
10
use Cake\Routing\Router;
11
12
class ConversationsController extends AppController
13
{
14
15
    /**
16
     * Initialization hook method.
17
     *
18
     * @return void
19
     */
20
    public function initialize()
21
    {
22
        parent::initialize();
23
24
        $this->loadComponent('RequestHandler');
25
    }
26
27
    /**
28
     * BeforeFilter handle.
29
     *
30
     * @param Event $event The beforeFilter event that was fired.
31
     *
32
     * @return void
33
     */
34
    public function beforeFilter(Event $event)
35
    {
36
        parent::beforeFilter($event);
37
38
        $this->Auth->deny();
39
40
        if (Configure::read('Conversations.enabled') === false && $this->request->action != 'maintenance') {
41
            $this->redirect(['action' => 'maintenance']);
42
        } elseif (Configure::read('Conversations.enabled') === true && $this->request->action == 'maintenance') {
43
            $this->redirect(['action' => 'index']);
44
        }
45
    }
46
47
    /**
48
     * Display all conversations for the user.
49
     *
50
     * @return void
51
     */
52
    public function index()
53
    {
54
        $this->ConversationsUsers = $this->loadModel('ConversationsUsers');
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. 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...
55
56
        $this->paginate = [
57
            'maxLimit' => Configure::read('Conversations.conversations_per_page')
58
        ];
59
        $conversations = $this->ConversationsUsers
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
60
            ->find()
61
            ->contain([
62
                'Users',
63
                'Conversations',
64
                'Conversations.Users' => function ($q) {
65
                    return $q->find('medium');
66
                },
67
                'Conversations.LastMessage',
68
                'Conversations.LastMessageUser'
69
            ])
70
            ->where([
71
                'ConversationsUsers.user_id' => $this->Auth->user('id'),
72
                'Conversations.conversation_open <>' => 2
73
            ])
74
            ->order([
75
                'ConversationsUsers.is_read' => 'ASC',
76
                'ConversationsUsers.is_star' => 'DESC',
77
                'Conversations.last_message_date' => 'DESC',
78
            ]);
79
80
        $conversations = $this->paginate($conversations);
81
82
        $this->set(compact('conversations'));
83
    }
84
85
    /**
86
     * Function to do an action when a user select a/many conversations.
87
     *
88
     * Action list :
89
     *      star : Conversations Important
90
     *      normal : Make normal conversation
91
     *      exit : Exit conversations
92
     *
93
     * @return void
94
     *
95
     * @throws NotFoundException
96
     */
97
    public function action()
98
    {
99
        if (!$this->request->is('ajax')) {
100
            throw new NotFoundException();
101
        }
102
103
        $actionAllowed = ['star', 'normal', 'exit'];
104
105 View Code Duplication
        if (!array_key_exists('action', $this->request->getParsedBody()) || !in_array($this->request->getData('action'), $actionAllowed)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
106
            $json = [];
107
            $json['error'] = '1';
108
            $json['message'] = __d('conversations', 'Action unknown.');
109
110
            $this->set(compact('json'));
111
            $this->set('_serialize', 'json');
112
113
            return;
114
        }
115
116 View Code Duplication
        if (!array_key_exists('conversations', $this->request->getParsedBody())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
117
            $json = [];
118
            $json['error'] = '1';
119
            $json['message'] = __d('conversations', 'You have not chosen any conversations.');
120
121
            $this->set(compact('json'));
122
            $this->set('_serialize', 'json');
123
124
            return;
125
        }
126
127
        $this->loadModel('ConversationsUsers');
128
129
        $action = $this->request->getData('action');
130
        $array = $this->request->getData('conversations');
131
132
        switch ($action) {
133 View Code Duplication
            case "star":
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
134
                foreach ($array as $conversationId) {
0 ignored issues
show
Bug introduced by
The expression $array of type null|string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
135
                    $this->ConversationsUsers->updateAll(
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
136
                        ['is_star' => 1],
137
                        [
138
                            'conversation_id' => $conversationId,
139
                            'user_id' => $this->Auth->user('id')
140
                        ]
141
                    );
142
                }
143
144
                $json['message'] = __d('conversations', 'Your conversation(s) has been Stared.');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$json was never initialized. Although not strictly required by PHP, it is generally a good practice to add $json = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
145
                $json['error'] = '0';
146
                $json['redirect'] = Router::url(['action' => 'index']);
147
148
                $this->set(compact('json'));
149
150
                break;
151
152 View Code Duplication
            case "normal":
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
153
                foreach ($array as $conversationId) {
0 ignored issues
show
Bug introduced by
The expression $array of type null|string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
154
                    $this->ConversationsUsers->updateAll(
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
155
                        ['is_star' => 0],
156
                        [
157
                            'conversation_id' => $conversationId,
158
                            'user_id' => $this->Auth->user('id')
159
                        ]
160
                    );
161
                }
162
163
                $json['message'] = __d('conversations', 'Your conversation(s) has been set normal.');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$json was never initialized. Although not strictly required by PHP, it is generally a good practice to add $json = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
164
                $json['error'] = '0';
165
                $json['redirect'] = Router::url(['action' => 'index']);
166
167
                $this->set(compact('json'));
168
                break;
169
170
            case "exit":
171
                foreach ($array as $conversationId) {
0 ignored issues
show
Bug introduced by
The expression $array of type null|string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
172
                    $user = $this->ConversationsUsers
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
173
                        ->find()
174
                        ->contain([
175
                            'Conversations'
176
                        ])
177
                        ->where([
178
                            'ConversationsUsers.user_id' => $this->Auth->user('id'),
179
                            'ConversationsUsers.conversation_id' => $conversationId
180
                        ])
181
                        ->first();
182
183
                    //Check if the user is the owner of the conversation.
184
                    if ($user->conversation->user_id == $this->Auth->user('id')) {
185
                        $conversation = $this->Conversations->get($conversationId);
0 ignored issues
show
Documentation introduced by
The property Conversations does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
186
                        $conversation->conversation_open = 2;
187
                        $this->Conversations->save($conversation);
0 ignored issues
show
Documentation introduced by
The property Conversations does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
188
                    } else {
189
                        $this->ConversationsUsers->delete($user);
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
190
191
                        $conversation = $this->Conversations->get($conversationId);
0 ignored issues
show
Documentation introduced by
The property Conversations does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
192
                        $conversation->recipient_count = $user->conversation->recipient_count - 1;
193
                        $this->Conversations->save($conversation);
0 ignored issues
show
Documentation introduced by
The property Conversations does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
194
                    }
195
                }
196
197
                $json['message'] = __d('conversations', 'You have left your conversation(s) successfully.');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$json was never initialized. Although not strictly required by PHP, it is generally a good practice to add $json = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
198
                $json['error'] = '0';
199
                $json['redirect'] = Router::url(['action' => 'index']);
200
201
                $this->set(compact('json'));
202
                break;
203
        }
204
205
        $this->set('_serialize', 'json');
206
    }
207
208
    /**
209
     * Create a new conversation.
210
     *
211
     * @return void
212
     */
213
    public function create()
214
    {
215
        $this->loadModel('Conversations');
216
        $conversation = $this->Conversations->newEntity($this->request->getParsedBody(), ['validate' => 'create']);
0 ignored issues
show
Documentation introduced by
The property Conversations does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
217
218
        if ($this->request->is('post')) {
219
            $users = str_replace(",", "", trim(strtolower($this->request->getData('users'))));
220
            $users = explode(" ", $users);
221
222
            //Check max users.
223
            if (!(count($users) <= Configure::read('Conversations.max_users_per_conversation'))) {
224
                $this->Flash->error(__d('conversations', 'You cannot invite more than {0} user(s) in this conversation.', Configure::read('Conversations.max_users_per_conversation')));
225
                $this->set(compact('conversation'));
226
227
                return;
228
            }
229
230
            $userMiniCount = false;
231
            $this->loadModel('Users');
232
233
            //We check if at least one user in all list exist.
234
            foreach ($users as $user) {
235
                $userCheck = $this->Users
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
236
                    ->find()
237
                    ->where([
238
                        'LOWER(Users.username)' => $user
239
                    ])
240
                    ->first();
241
242
                //If an user exist and if the user is not the own of the conversation.
243
                if ($userCheck && $userCheck->id != $this->Auth->user('id')) {
244
                    $userMiniCount = true;
245
                    break;
246
                }
247
            }
248
249
            if ($userMiniCount === false) {
250
                $this->Flash->error(__d('conversations', 'Please enter at least one valid recipient.'));
251
                $this->set(compact('conversation'));
252
253
                return;
254
            }
255
256
            $conversation->user_id = $this->Auth->user('id');
257
            $conversation->reply_count = 1;
258
            $conversation->recipient_count = 1;
259
            $conversation->last_message_user_id = $this->Auth->user('id');
260
            $conversation->last_message_date = new Time();
261
262
            if ($conversation = $this->Conversations->save($conversation)) {
0 ignored issues
show
Documentation introduced by
The property Conversations does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
263
                $this->loadModel('ConversationsMessages');
264
                $this->loadModel('ConversationsUsers');
265
266
                $data = [];
267
                $data['message'] = $this->request->getData('message');
268
                $data['conversation_id'] = $conversation->id;
269
                $data['user_id'] = $this->Auth->user('id');
270
271
                $entity = $this->ConversationsMessages->newEntity($data);
0 ignored issues
show
Documentation introduced by
The property ConversationsMessages does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
272
                $message = $this->ConversationsMessages->save($entity);
0 ignored issues
show
Documentation introduced by
The property ConversationsMessages does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
273
274
                $data = [];
275
                $data['conversation_id'] = $conversation->id;
276
                $data['user_id'] = $this->Auth->user('id');
277
278
                $entity = $this->ConversationsUsers->newEntity($data);
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
279
                $user = $this->ConversationsUsers->save($entity);
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
280
281
                $this->Conversations->updateAll(
0 ignored issues
show
Documentation introduced by
The property Conversations does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
282
                    [
283
                        'first_message_id' => $message->id,
284
                        'last_message_id' => $message->id
285
                    ],
286
                    [
287
                        'id' => $conversation->id
288
                    ]
289
                );
290
291
                //Save all invited users.
292
                foreach ($users as $user) {
293
                    $userExist = $this->Users
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
294
                        ->find()
295
                        ->where([
296
                            'LOWER(Users.username)' => $user
297
                        ])
298
                        ->first();
299
300
                    //If the user exist.
301
                    if (is_null($userExist)) {
302
                        break;
303
                    }
304
305
                    //Check if the user is not already in the conversation.
306
                    $conversUserCheck = $this->ConversationsUsers
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
307
                        ->find()
308
                        ->where([
309
                            'ConversationsUsers.conversation_id' => $conversation->id,
310
                            'ConversationsUsers.user_id' => $userExist->id
311
                        ])
312
                        ->first();
313
314
                    if (!is_null($conversUserCheck)) {
315
                        break;
316
                    }
317
318
                    $data = [];
319
                    $data['conversation_id'] = $conversation->id;
320
                    $data['user_id'] = $userExist->id;
321
322
                    $entity = $this->ConversationsUsers->newEntity($data);
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
323
                    $user = $this->ConversationsUsers->save($entity);
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
324
325
                    $expression = new QueryExpression('recipient_count = recipient_count + 1');
326
                    $this->Conversations->updateAll(
0 ignored issues
show
Documentation introduced by
The property Conversations does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
327
                        [$expression],
328
                        [
329
                            'id' => $conversation->id
330
                        ]
331
                    );
332
333
                    //Notifications Event.
334
                    $this->eventManager()->attach(new Notifications());
0 ignored issues
show
Documentation introduced by
new \App\Event\Notifications() is of type object<App\Event\Notifications>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Deprecated Code introduced by
The method Cake\Event\EventManager::attach() has been deprecated with message: 3.0.0 Use on() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
335
                    $event = new Event('Model.Notifications.dispatch', $this, [
336
                        'sender_id' => $this->Auth->user('id'),
337
                        'conversation_id' => $conversation->id,
338
                        'type' => 'conversation.reply'
339
                    ]);
340
                    $this->eventManager()->dispatch($event);
341
                }
342
343
                $this->Flash->success(__d('conversations', 'Your conversation has been created successfully !'));
344
                $this->redirect([
345
                    '_name' => 'conversations-view',
346
                    'slug' => $conversation->title,
347
                    'id' => $conversation->id
348
                ]);
349
            }
350
        }
351
352
        $this->set(compact('conversation'));
353
    }
354
355
    /**
356
     * Display a conversation.
357
     *
358
     * @return void|\Cake\Network\Response
359
     */
360
    public function view()
361
    {
362
        $this->loadModel('ConversationsUsers');
363
364
        $conversation = $this->ConversationsUsers
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
365
            ->find()
366
            ->contain([
367
                'Users',
368
                'Conversations',
369
                'Conversations.LastMessage',
370
                'Conversations.LastMessageUser'
371
            ])
372
            ->where([
373
                'ConversationsUsers.conversation_id' => $this->request->id,
374
                'ConversationsUsers.user_id' => $this->Auth->user('id'),
375
                'Conversations.conversation_open <>' => 2
376
            ])
377
            ->first();
378
379
        if (is_null($conversation)) {
380
            $this->Flash->error(__d('conversations', "This conversation doesn't exist or has been deleted."));
381
382
            return $this->redirect(['action' => 'index']);
383
        }
384
385
        $this->loadModel('ConversationsMessages');
386
387
        $this->paginate = [
388
            'maxLimit' => Configure::read('Conversations.messages_per_page')
389
        ];
390
391
        $messages = $this->ConversationsMessages
0 ignored issues
show
Documentation introduced by
The property ConversationsMessages does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
392
            ->find()
393
            ->contain([
394
                'Users' => function ($q) {
395
                    return $q->find('full')->formatResults(function ($users) {
396
                        return $users->map(function ($user) {
397
                            $user->online = $this->SessionsActivity->getOnlineStatus($user);
0 ignored issues
show
Documentation introduced by
The property SessionsActivity does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
398
399
                            return $user;
400
                        });
401
                    });
402
                },
403
                'Users.Groups',
404
                'LastEditUsers' => function ($q) {
405
                    return $q->find('short');
406
                },
407
            ])
408
            ->where([
409
                'ConversationsMessages.conversation_id' => $this->request->id
410
            ])
411
            ->order([
412
                'ConversationsMessages.created' => 'ASC'
413
            ]);
414
415
        $messages = $this->paginate($messages);
416
417
        //Update "is_read" for the current user.
418
        $user = $this->ConversationsUsers->get($conversation->id);
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
419
        $user->is_read = 1;
420
        $this->ConversationsUsers->save($user);
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
421
422
        //Current user.
423
        $this->loadModel('Users');
424
        $currentUser = $this->Users
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
425
            ->find()
426
            ->contain([
427
                'Groups' => function ($q) {
428
                    return $q->select(['id', 'is_staff']);
429
                }
430
            ])
431
            ->where([
432
                'Users.id' => $this->Auth->user('id')
433
            ])
434
            ->select(['id', 'group_id'])
435
            ->first();
436
437
        //Build the newEntity for the comment form.
438
        $messageForm = $this->ConversationsMessages->newEntity();
0 ignored issues
show
Documentation introduced by
The property ConversationsMessages does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
439
440
        $this->set(compact('conversation', 'messages', 'currentUser', 'messageForm'));
441
    }
442
443
    /**
444
     * Action to search some users when adding an user in a conversation.
445
     *
446
     * @return void
447
     *
448
     * @throws \Cake\Network\Exception\NotFoundException
449
     */
450
    public function inviteMember()
451
    {
452
        if (!$this->request->is('ajax')) {
453
            throw new NotFoundException();
454
        }
455
        $keyword = strtolower($this->request->getQuery('query'));
456
457
        $this->loadModel('Users');
458
        $users = $this->Users
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
459
            ->find()
460
            ->where(function ($q) use ($keyword) {
461
                    return $q
462
                        ->like('LOWER(Users.username)', "%$keyword%");
463
            })
464
            ->limit(12)
465
            ->toArray();
466
467
        foreach ($users as $user) {
468
            $json[] = h($user->username);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$json was never initialized. Although not strictly required by PHP, it is generally a good practice to add $json = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
469
        }
470
471
        $this->set(compact('json'));
472
        $this->set('_serialize', 'json');
473
    }
474
475
    /**
476
     * Quote a post.
477
     *
478
     * @throws \Cake\Network\Exception\NotFoundException
479
     *
480
     * @return mixed
481
     */
482
    public function quote()
483
    {
484
        if (!$this->request->is('ajax')) {
485
            throw new NotFoundException();
486
        }
487
488
        $this->loadModel('ConversationsMessages');
489
490
        $message = $this->ConversationsMessages
0 ignored issues
show
Documentation introduced by
The property ConversationsMessages does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
491
            ->find()
492
            ->where([
493
                'ConversationsMessages.id' => $this->request->id
494
            ])
495
            ->contain([
496
                'Users' => function ($q) {
497
                        return $q->find('short');
498
                }
499
            ])
500
            ->first();
501
502
        $json = [];
503
504
        if (!is_null($message)) {
505
            $message->toArray();
506
507
            $url = Router::url(['action' => 'go', $message->id]);
508
            $text = __d('conversations', 'has said :');
509
510
            //Build the quote.
511
            $json['message'] = <<<EOT
512
<div>
513
    <div>
514
        <a href="{$url}">
515
            <strong>{$message->user->full_name} {$text}</strong>
516
        </a>
517
    </div>
518
    <blockquote>
519
        $message->message
520
    </blockquote>
521
</div><p>&nbsp;</p><p>&nbsp;</p>
522
EOT;
523
524
            $json['error'] = false;
525
526
            $this->set(compact('json'));
527
        } else {
528
            $json['post'] = __d('conversations', "This message doesn't exist.");
529
            $json['error'] = true;
530
531
            $this->set(compact('json'));
532
        }
533
534
        //Send response in JSON.
535
        $this->set('_serialize', 'json');
536
    }
537
538
    /**
539
     * Get the form to edit a message.
540
     *
541
     * @throws \Cake\Network\Exception\NotFoundException When it's not an AJAX request.
542
     *
543
     * @return void
544
     */
545
    public function getEditMessage()
546
    {
547
        if (!$this->request->is('ajax')) {
548
            throw new NotFoundException();
549
        }
550
551
        $this->loadModel('ConversationsMessages');
552
        $this->viewBuilder()->layout(false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Deprecated Code introduced by
The method Cake\View\ViewBuilder::layout() has been deprecated with message: 3.4.0 Use setLayout()/getLayout() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
553
554
        $message = $this->ConversationsMessages
0 ignored issues
show
Documentation introduced by
The property ConversationsMessages does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
555
            ->find()
556
            ->where([
557
                'ConversationsMessages.id' => $this->request->getData('id')
558
            ])
559
            ->first();
560
561
        $json = [
562
            'error' => false,
563
            'errorMessage' => ''
564
        ];
565
566 View Code Duplication
        if (is_null($message)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
567
            $json['error'] = true;
568
            $json['errorMessage'] = __d('conversations', "This message doesn't exist or has been deleted !");
569
570
            $this->set(compact('json'));
571
572
            return;
573
        }
574
575
        //Current user.
576
        $this->loadModel('Users');
577
        $currentUser = $this->Users
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
578
            ->find()
579
            ->contain([
580
                'Groups' => function ($q) {
581
                    return $q->select(['id', 'is_staff']);
582
                }
583
            ])
584
            ->where([
585
                'Users.id' => $this->Auth->user('id')
586
            ])
587
            ->select(['id', 'group_id'])
588
            ->first();
589
590
        if ($message->user_id != $this->Auth->user('id') && !$currentUser->group->is_staff) {
591
            $json['error'] = true;
592
            $json['errorMessage'] = __d('conversations', "You don't have the authorization to edit this message !");
593
594
            $this->set(compact('json'));
595
596
            return;
597
        }
598
599
        $this->set(compact('json', 'message'));
600
    }
601
602
    /**
603
     * Edit a message.
604
     *
605
     * @param int $id Id of the message.
606
     *
607
     * @return \Cake\Network\Response
608
     */
609
    public function messageEdit($id = null)
610
    {
611
        if (!$this->request->is(['post', 'put'])) {
612
            throw new NotFoundException();
613
        }
614
615
        $this->loadModel('ConversationsMessages');
616
617
        $message = $this->ConversationsMessages
0 ignored issues
show
Documentation introduced by
The property ConversationsMessages does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
618
            ->find()
619
            ->where([
620
                'ConversationsMessages.id' => $id
621
            ])
622
            ->first();
623
624
        if (is_null($message)) {
625
            $this->Flash->error(__d('conversations', "This post doesn't exist or has been deleted !"));
626
627
            return $this->redirect($this->referer());
0 ignored issues
show
Bug introduced by
It seems like $this->referer() targeting Cake\Controller\Controller::referer() can also be of type object<Cake\Http\ServerRequest>; however, Cake\Controller\Controller::redirect() does only seem to accept string|array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
628
        }
629
630
        //Current user.
631
        $this->loadModel('Users');
632
        $currentUser = $this->Users
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
633
            ->find()
634
            ->contain([
635
                'Groups' => function ($q) {
636
                    return $q->select(['id', 'is_staff']);
637
                }
638
            ])
639
            ->where([
640
                'Users.id' => $this->Auth->user('id')
641
            ])
642
            ->select(['id', 'group_id'])
643
            ->first();
644
645
        if ($message->user_id != $this->Auth->user('id') && !$currentUser->group->is_staff) {
646
            $this->Flash->error(__d('conversations', "You don't have the authorization to edit this post !"));
647
648
            return $this->redirect($this->referer());
0 ignored issues
show
Bug introduced by
It seems like $this->referer() targeting Cake\Controller\Controller::referer() can also be of type object<Cake\Http\ServerRequest>; however, Cake\Controller\Controller::redirect() does only seem to accept string|array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
649
        }
650
651
        $this->ConversationsMessages->patchEntity($message, $this->request->getParsedBody());
0 ignored issues
show
Documentation introduced by
The property ConversationsMessages does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
652
        $message->last_edit_date = new Time();
653
        $message->last_edit_user_id = $this->Auth->user('id');
654
        $message->edit_count++;
655
656
        if ($this->ConversationsMessages->save($message)) {
0 ignored issues
show
Documentation introduced by
The property ConversationsMessages does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
657
            $this->Flash->success(__d('conversations', 'This message has been edited successfully !'));
658
        }
659
660
        return $this->redirect(['action' => 'go', $message->id]);
661
    }
662
663
    /**
664
     * Redirect an user to a conversation, page and message.
665
     *
666
     * @param int $messageId Id of the message.
667
     *
668
     * @return \Cake\Network\Response
669
     */
670 View Code Duplication
    public function go($messageId = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
671
    {
672
        $this->loadModel('ConversationsMessages');
673
674
        $message = $this->ConversationsMessages
0 ignored issues
show
Documentation introduced by
The property ConversationsMessages does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
675
            ->find()
676
            ->contain([
677
                'Conversations'
678
            ])
679
            ->where([
680
                'ConversationsMessages.id' => $messageId
681
            ])
682
            ->first();
683
684
        if (is_null($message)) {
685
            $this->Flash->error(__d('conversations', "This message doesn't exist or has been deleted."));
686
687
            return $this->redirect(['controller' => 'conversations', 'action' => 'index']);
688
        }
689
690
        $message->toArray();
691
692
        //Count the number of messages before this message.
693
        $messagesBefore = $this->ConversationsMessages
0 ignored issues
show
Documentation introduced by
The property ConversationsMessages does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
694
            ->find()
695
            ->where([
696
                'ConversationsMessages.conversation_id' => $message->conversation_id,
697
                'ConversationsMessages.created <' => $message->created
698
            ])
699
            ->count();
700
701
        //Get the number of messages per page.
702
        $messagesPerPage = Configure::read('Conversations.messages_per_page');
703
704
        //Calculate the page.
705
        $page = ceil($messagesBefore / $messagesPerPage);
706
707
        $page = ($page > 1) ? $page : 1;
708
709
        //Redirect the user.
710
        return $this->redirect([
711
            '_name' => 'conversations-view',
712
            'slug' => $message->conversation->title,
713
            'id' => $message->conversation->id,
714
            '?' => ['page' => $page],
715
            '#' => 'message-' . $messageId
716
        ]);
717
    }
718
719
    /**
720
     * Function to kick an user from a conversation.
721
     *
722
     * @return void
723
     */
724
    public function kick()
725
    {
726
        if (!$this->request->is('ajax')) {
727
            throw new NotFoundException();
728
        }
729
730
        $this->loadModel('ConversationsUsers');
731
732
        $currentUser = $this->ConversationsUsers
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
733
            ->find()
734
            ->contain([
735
                'Conversations',
736
                'Users' => function ($q) {
737
                    return $q->find('short');
738
                },
739
                'Users.Groups' => function ($q) {
740
                    return $q->select(['id', 'is_staff']);
741
                }
742
            ])
743
            ->where([
744
                'ConversationsUsers.user_id' => $this->Auth->user('id'),
745
                'ConversationsUsers.conversation_id' => $this->request->id
746
            ])
747
            ->first();
748
749
        //Check if the current user is the owner of this conversation or if he is not a staff member.
750
        if ($currentUser->user_id != $currentUser->conversation->user_id && !$currentUser->user->group->is_staff) {
751
            $json['message'] = __d('conversations', 'You cannot kick this user from this conversation.');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$json was never initialized. Although not strictly required by PHP, it is generally a good practice to add $json = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
752
            $json['error'] = true;
753
754
            $this->set(compact('json'));
755
            $this->set('_serialize', 'json');
756
757
            return;
758
        }
759
760
        $user = $this->ConversationsUsers
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
761
            ->find()
762
            ->contain([
763
                'Conversations',
764
                'Users' => function ($q) {
765
                    return $q->find('short');
766
                },
767
                'Users.Groups' => function ($q) {
768
                    return $q->select(['id', 'is_staff']);
769
                }
770
            ])
771
            ->where([
772
                'ConversationsUsers.user_id' => $this->request->user_id,
773
                'ConversationsUsers.conversation_id' => $this->request->id
774
            ])
775
            ->first();
776
777
        //Check if the user to kick is in the conversation and if he is not owner of this conversation and if he is not a staff member.
778
        if (is_null($user) || $this->request->user_id == $currentUser->conversation->user_id || $user->user->group->is_staff) {
779
            $json['message'] = __d('conversations', 'You cannot kick this user from this conversation.');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$json was never initialized. Although not strictly required by PHP, it is generally a good practice to add $json = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
780
            $json['error'] = true;
781
782
            $this->set(compact('json'));
783
            $this->set('_serialize', 'json');
784
785
            return;
786
        }
787
788
        $this->ConversationsUsers->delete($user);
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
789
790
        $expression = new QueryExpression('recipient_count = recipient_count - 1');
791
        $this->Conversations->updateAll(
0 ignored issues
show
Documentation introduced by
The property Conversations does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
792
            [$expression],
793
            [
794
                'id' => $this->request->id
795
            ]
796
        );
797
798
        $json['message'] = __d('conversations', 'This user has been kicked successfully.');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$json was never initialized. Although not strictly required by PHP, it is generally a good practice to add $json = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
799
        $json['error'] = false;
800
        $json['id'] = $this->request->user_id;
0 ignored issues
show
Bug introduced by
The property user_id does not seem to exist in Cake\Http\ServerRequest.

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...
801
        $json['recipients'] = $currentUser->conversation->recipient_count - 1;
802
803
        $this->set(compact('json'));
804
        $this->set('_serialize', 'json');
805
    }
806
807
    /**
808
     * Reply to a conversation.
809
     *
810
     * @return void|\Cake\Network\Response
811
     */
812
    public function reply()
813
    {
814
        $this->loadModel('ConversationsMessages');
815
816
        if ($this->request->is('post')) {
817
            $conversation = $this->Conversations
0 ignored issues
show
Documentation introduced by
The property Conversations does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
818
                ->find()
819
                ->where(['Conversations.id' => $this->request->id])
820
                ->first();
821
822
            $this->loadModel('ConversationsUsers');
823
            $user = $this->ConversationsUsers
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
824
                ->find()
825
                ->where([
826
                    'ConversationsUsers.conversation_id' => $this->request->id,
827
                    'ConversationsUsers.user_id' => $this->Auth->user('id')
828
                ])
829
                ->first();
830
831
            //Check if the conversation is found.
832
            if (is_null($user) || is_null($conversation) || $conversation->conversation_open == 2) {
833
                $this->Flash->error(__d('conversations', "This conversation doesn't exist or has been deleted !"));
834
835
                return $this->redirect($this->referer());
0 ignored issues
show
Bug introduced by
It seems like $this->referer() targeting Cake\Controller\Controller::referer() can also be of type object<Cake\Http\ServerRequest>; however, Cake\Controller\Controller::redirect() does only seem to accept string|array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
836
            }
837
838
            //Check if the conversation is open.
839 View Code Duplication
            if ($conversation->conversation_open == false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
840
                $this->Flash->error(__d('conversations', 'This conversation is closed, you cannot reply.'));
841
842
                return $this->redirect($this->referer());
0 ignored issues
show
Bug introduced by
It seems like $this->referer() targeting Cake\Controller\Controller::referer() can also be of type object<Cake\Http\ServerRequest>; however, Cake\Controller\Controller::redirect() does only seem to accept string|array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
843
            }
844
845
            //Build the newEntity for the post form.
846
            $this->request = $this->request
847
                ->withData('conversation.last_post_date', new Time())
848
                ->withData('conversation.last_post_user_id', $this->Auth->user('id'))
849
                ->withData('user_id', $this->Auth->user('id'))
850
                ->withData('conversation_id', $this->request->id);
851
852
            $message = $this->ConversationsMessages->newEntity($this->request->getParsedBody(), [
0 ignored issues
show
Documentation introduced by
The property ConversationsMessages does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
853
                'associated' => ['Conversations'],
854
                'validate' => 'create'
855
            ]);
856
857
            //Handle validation errors (Due to the redirect)
858
            if (!empty($message->errors())) {
859
                $this->Flash->conversationsReply('Validation errors', [
860
                    'key' => 'ConversationsReply',
861
                    'params' => [
862
                        'errors' => $message->errors()
863
                    ]
864
                ]);
865
866
                return $this->redirect($this->referer());
0 ignored issues
show
Bug introduced by
It seems like $this->referer() targeting Cake\Controller\Controller::referer() can also be of type object<Cake\Http\ServerRequest>; however, Cake\Controller\Controller::redirect() does only seem to accept string|array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
867
            }
868
869
            if ($message->conversation->isNew() === true) {
870
                $message->conversation->isNew(false);
871
            }
872
873
            $message->conversation->accessible('id', true);
874
            $message->conversation->id = $this->request->id;
0 ignored issues
show
Bug introduced by
The property id does not seem to exist in Cake\Http\ServerRequest.

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...
875
876
            if ($message = $this->ConversationsMessages->save($message)) {
0 ignored issues
show
Documentation introduced by
The property ConversationsMessages does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
877
                //Update the last message id for the conversation.
878
                $this->loadModel('Conversations');
879
                $conversation = $this->Conversations->get($this->request->id);
0 ignored issues
show
Documentation introduced by
The property Conversations does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
880
                $conversation->last_message_id = $message->id;
881
                $conversation->last_message_date = new Time();
882
                $conversation->last_message_user_id = $this->Auth->user('id');
883
                $this->Conversations->save($conversation);
0 ignored issues
show
Documentation introduced by
The property Conversations does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
884
885
                //Notifications Event.
886
                $this->eventManager()->attach(new Notifications());
0 ignored issues
show
Documentation introduced by
new \App\Event\Notifications() is of type object<App\Event\Notifications>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Deprecated Code introduced by
The method Cake\Event\EventManager::attach() has been deprecated with message: 3.0.0 Use on() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
887
                $event = new Event('Model.Notifications.dispatch', $this, [
888
                    'sender_id' => $this->Auth->user('id'),
889
                    'conversation_id' => $conversation->id,
890
                    'type' => 'conversation.reply'
891
                ]);
892
                $this->eventManager()->dispatch($event);
893
894
                $conversationOpen = !is_null($this->request->getData('conversation.conversation_open')) ? $this->request->getData('conversation.conversation_open') : true;
895
896
                if ($conversationOpen == false) {
897
                    $this->Flash->success(__d('conversations', 'Your reply has been posted successfully and the conversation has been closed !'));
898
                } else {
899
                    $this->Flash->success(__d('conversations', 'Your reply has been posted successfully !'));
900
                }
901
902
                //Redirect the user to the last page of the article.
903
                return $this->redirect([
904
                    'controller' => 'conversations',
905
                    'action' => 'go',
906
                    $message->id
907
                ]);
908
            }
909
        }
910
911
        $this->redirect($this->referer());
0 ignored issues
show
Bug introduced by
It seems like $this->referer() targeting Cake\Controller\Controller::referer() can also be of type object<Cake\Http\ServerRequest>; however, Cake\Controller\Controller::redirect() does only seem to accept string|array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
912
    }
913
914
    /**
915
     * Edit a conversation.
916
     *
917
     * @return \Cake\Network\Response
918
     */
919
    public function edit()
920
    {
921
        $this->loadModel('Conversations');
922
923
        if ($this->request->is('put')) {
924
            $conversation = $this->Conversations
0 ignored issues
show
Documentation introduced by
The property Conversations does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
925
                ->find()
926
                ->where([
927
                    'Conversations.id' => $this->request->id
928
                ])
929
                ->first();
930
931
            //Check if the conversation is found.
932 View Code Duplication
            if (is_null($conversation)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
933
                $this->Flash->error(__d('conversations', "This conversation doesn't exist or has been deleted !"));
934
935
                return $this->redirect($this->referer());
0 ignored issues
show
Bug introduced by
It seems like $this->referer() targeting Cake\Controller\Controller::referer() can also be of type object<Cake\Http\ServerRequest>; however, Cake\Controller\Controller::redirect() does only seem to accept string|array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
936
            }
937
938
            //Check if the user has the permission to edit it.
939 View Code Duplication
            if ($this->Auth->isAuthorized() === false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
940
                $this->Flash->error(__d('conversations', "You don't have the authorization to edit this conversation !"));
941
942
                return $this->redirect([
943
                    'controller' => 'conversations',
944
                    'action' => 'go',
945
                    $conversation->last_message_id
946
                ]);
947
            }
948
949
            $this->Conversations->patchEntity($conversation, $this->request->getParsedBody(), ['validate' => 'edit']);
0 ignored issues
show
Documentation introduced by
The property Conversations does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
950
951
            if ($this->Conversations->save($conversation)) {
0 ignored issues
show
Documentation introduced by
The property Conversations does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
952
                if ($conversation->conversation_open == false) {
953
                    $this->Flash->success(__d('conversations', 'Your conversation has been edited and closed successfully !'));
954
                } else {
955
                    $this->Flash->success(__d('conversations', 'Your conversation has been edited successfully !'));
956
                }
957
958
                return $this->redirect([
959
                    'controller' => 'conversations',
960
                    'action' => 'go',
961
                    $conversation->last_message_id
962
                ]);
963
            }
964
        }
965
966
        $this->redirect($this->referer());
0 ignored issues
show
Bug introduced by
It seems like $this->referer() targeting Cake\Controller\Controller::referer() can also be of type object<Cake\Http\ServerRequest>; however, Cake\Controller\Controller::redirect() does only seem to accept string|array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
967
    }
968
969
    /**
970
     * Function to invite user(s) in a conversation.
971
     *
972
     * @return void|\Cake\Network\Response
973
     */
974
    public function invite()
975
    {
976
        $this->loadModel('ConversationsUsers');
977
978
        $conversation = $this->ConversationsUsers
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
979
            ->find()
980
            ->contain([
981
                'Conversations',
982
                'Users',
983
                'Users.Groups'
984
            ])
985
            ->where([
986
                'ConversationsUsers.conversation_id' => $this->request->id,
987
                'ConversationsUsers.user_id' => $this->Auth->user('id')
988
            ])
989
            ->first();
990
991 View Code Duplication
        if (is_null($conversation) || $conversation->conversation->conversation_open != 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
992
            $this->Flash->error(__d('conversations', 'This conversation is closed or has been deleted !'));
993
994
            return $this->redirect($this->referer());
0 ignored issues
show
Bug introduced by
It seems like $this->referer() targeting Cake\Controller\Controller::referer() can also be of type object<Cake\Http\ServerRequest>; however, Cake\Controller\Controller::redirect() does only seem to accept string|array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
995
        }
996
997
        if (!$conversation->conversation->open_invite && $conversation->conversation->user_id != $this->Auth->user('id') && !$conversation->user->group->is_staff) {
998
            $this->Flash->error(__d('conversations', "You don't have the authorization to invite in this conversation !"));
999
1000
            return $this->redirect($this->referer());
0 ignored issues
show
Bug introduced by
It seems like $this->referer() targeting Cake\Controller\Controller::referer() can also be of type object<Cake\Http\ServerRequest>; however, Cake\Controller\Controller::redirect() does only seem to accept string|array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
1001
        }
1002
1003
        if ($this->request->is(['post', 'put'])) {
1004
            $users = str_replace(",", "", trim(strtolower($this->request->getData('users'))));
1005
            $users = explode(" ", $users);
1006
1007
            $maxUsersCheck = $this->ConversationsUsers
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
1008
                ->find()
1009
                ->where([
1010
                    'ConversationsUsers.conversation_id' => $this->request->id
1011
                ])
1012
                ->count();
1013
1014
            //Check max users.
1015
            if (count($users) + $maxUsersCheck >= Configure::read('Conversations.max_users_per_conversation')) {
1016
                $this->Flash->error(__d('conversations', 'You cannot invite more than {0} user(s) in this conversation.', Configure::read('Conversations.max_users_per_conversation')));
1017
1018
                return $this->redirect($this->referer());
0 ignored issues
show
Bug introduced by
It seems like $this->referer() targeting Cake\Controller\Controller::referer() can also be of type object<Cake\Http\ServerRequest>; however, Cake\Controller\Controller::redirect() does only seem to accept string|array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
1019
            }
1020
1021
            $this->loadModel('Users');
1022
            $this->loadModel('Conversations');
1023
1024
            foreach ($users as $user) {
1025
                $user = $this->Users
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
1026
                    ->find()
1027
                    ->where([
1028
                        'LOWER(Users.username)' => $user
1029
                    ])
1030
                    ->first();
1031
1032
                if (!is_null($user)) {
1033
                    $check = $this->ConversationsUsers
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
1034
                        ->find()
1035
                        ->where([
1036
                            'ConversationsUsers.conversation_id' => $this->request->id,
1037
                            'ConversationsUsers.user_id' => $user->id
1038
                        ])
1039
                        ->first();
1040
1041
                    if (is_null($check)) {
1042
                        $data = [];
1043
                        $data['conversation_id'] = $this->request->id;
0 ignored issues
show
Bug introduced by
The property id does not seem to exist in Cake\Http\ServerRequest.

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...
1044
                        $data['user_id'] = $user->id;
1045
1046
                        $entity = $this->ConversationsUsers->newEntity($data);
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
1047
                        $this->ConversationsUsers->save($entity);
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
1048
1049
                        $expression = new QueryExpression('recipient_count = recipient_count + 1');
1050
                        $this->Conversations->updateAll(
0 ignored issues
show
Documentation introduced by
The property Conversations does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
1051
                            [$expression],
1052
                            [
1053
                                'id' => $this->request->id
1054
                            ]
1055
                        );
1056
                    }
1057
                }
1058
            }
1059
1060
            $this->Flash->success(__d('conversations', 'Your user(s) has been added successfully.'));
1061
        }
1062
1063
        return $this->redirect([
1064
            'controller' => 'conversations',
1065
            'action' => 'go',
1066
            $conversation->conversation->last_message_id
1067
        ]);
1068
    }
1069
1070
    /**
1071
     * Function to leave a conversation.
1072
     *
1073
     * @return void|\Cake\Network\Response
1074
     */
1075
    public function leave()
1076
    {
1077
        $this->loadModel('ConversationsUsers');
1078
1079
        $user = $this->ConversationsUsers
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
1080
            ->find()
1081
            ->contain([
1082
                'Conversations'
1083
            ])
1084
            ->where([
1085
                'ConversationsUsers.conversation_id' => $this->request->id,
1086
                'ConversationsUsers.user_id' => $this->Auth->user('id')
1087
            ])
1088
            ->first();
1089
1090
        if (is_null($user)) {
1091
            $this->Flash->error(__d('conversations', 'You are not in this conversation.'));
1092
1093
            return $this->redirect($this->referer());
0 ignored issues
show
Bug introduced by
It seems like $this->referer() targeting Cake\Controller\Controller::referer() can also be of type object<Cake\Http\ServerRequest>; however, Cake\Controller\Controller::redirect() does only seem to accept string|array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
1094
        }
1095
1096
        if ($user->conversation->user_id != $this->Auth->user('id')) {
1097
            $this->loadModel('Conversations');
1098
1099
            $this->ConversationsUsers->delete($user);
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
1100
1101
            $expression = new QueryExpression('recipient_count = recipient_count - 1');
1102
            $this->Conversations->updateAll(
0 ignored issues
show
Documentation introduced by
The property Conversations does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
1103
                [$expression],
1104
                [
1105
                    'id' => $this->request->id
1106
                ]
1107
            );
1108
1109
            $this->Flash->success(__d('conversations', 'You have left the conversation successfully.'));
1110
1111
            return $this->redirect(['controller' => 'conversations', 'action' => 'index']);
1112 View Code Duplication
        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1113
            $this->Flash->error(__d('conversations', 'You can not leave your own conversation.'));
1114
1115
            return $this->redirect([
1116
                'controller' => 'conversations',
1117
                'action' => 'go',
1118
                $user->conversation->last_message_id
1119
            ]);
1120
        }
1121
    }
1122
1123
    /**
1124
     * Search conversations.
1125
     *
1126
     * @return void
1127
     */
1128
    public function search()
1129
    {
1130
        $this->loadModel('ConversationsUsers');
1131
1132
        //Check the keyword to search. (For pagination)
1133 View Code Duplication
        if (!empty($this->request->getData('search'))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1134
            $keyword = $this->request->getData('search');
1135
            $this->request->session()->write('Search.Conversations.Keyword', $keyword);
1136
        } else {
1137
            if ($this->request->session()->read('Search.Conversations.Keyword')) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->request->session(...Conversations.Keyword') of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
1138
                $keyword = $this->request->session()->read('Search.Conversations.Keyword');
1139
            } else {
1140
                $keyword = '';
1141
            }
1142
        }
1143
1144
        //Pagination
1145
        $this->paginate = [
1146
            'maxLimit' => Configure::read('Conversations.conversations_per_page')
1147
        ];
1148
1149
        $conversations = $this->ConversationsUsers
0 ignored issues
show
Documentation introduced by
The property ConversationsUsers does not exist on object<App\Controller\ConversationsController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
1150
            ->find()
1151
            ->contain([
1152
                'Users',
1153
                'Conversations',
1154
                'Conversations.Users' => function ($q) {
1155
                    return $q->find('medium');
1156
                },
1157
                'Conversations.LastMessage',
1158
                'Conversations.LastMessageUser'
1159
            ])
1160
            ->where([
1161
                'ConversationsUsers.user_id' => $this->Auth->user('id'),
1162
                'Conversations.conversation_open <>' => 2
1163
            ])
1164
            ->andWhere(function ($q) use ($keyword) {
1165
                    return $q
1166
                        ->like('Conversations.title', "%$keyword%");
1167
            })
1168
            ->order([
1169
                'ConversationsUsers.is_read' => 'ASC',
1170
                'ConversationsUsers.is_star' => 'DESC',
1171
                'Conversations.last_message_date' => 'DESC',
1172
            ]);
1173
1174
        $conversations = $this->paginate($conversations);
1175
1176
        $this->set(compact('conversations', 'keyword'));
1177
    }
1178
1179
    /**
1180
     * Action to render the maintenance page.
1181
     *
1182
     * @return void
1183
     */
1184
    public function maintenance()
1185
    {
1186
    }
1187
}
1188