Completed
Push — v3 ( 8d65fc...320a43 )
by Fèvre
03:08
created

UsersController::premium()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 15

Duplication

Lines 25
Ratio 100 %

Importance

Changes 0
Metric Value
dl 25
loc 25
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
namespace App\Controller;
3
4
use App\Event\Badges;
5
use App\Event\Notifications;
6
use App\Event\Statistics;
7
use App\Utility\Users as UsersUtility;
8
use Cake\Auth\DefaultPasswordHasher;
9
use Cake\Core\Configure;
10
use Cake\Event\Event;
11
use Cake\I18n\Time;
12
use Cake\Network\Email\Email;
13
14
class UsersController extends AppController
15
{
16
17
    /**
18
     * Initialize handle.
19
     *
20
     * @return void
21
     */
22
    public function initialize()
23
    {
24
        parent::initialize();
25
26
        $action = $this->request->action;
0 ignored issues
show
Bug introduced by
The property action does not seem to exist in Cake\Network\Request.

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...
27
28
        if ($action === 'login' || $action === 'forgotPassword') {
29
            $this->loadComponent('Recaptcha.Recaptcha');
30
        }
31
    }
32
33
    /**
34
     * BeforeFilter handle.
35
     *
36
     * @param Event $event The beforeFilter event that was fired.
37
     *
38
     * @return void
39
     */
40
    public function beforeFilter(Event $event)
41
    {
42
        parent::beforeFilter($event);
43
44
        $this->Auth->allow(['index', 'logout', 'profile', 'forgotPassword', 'resetPassword']);
45
    }
46
47
    /**
48
     * Display all Users.
49
     *
50
     * @return void
51
     */
52 View Code Duplication
    public function index()
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...
53
    {
54
        $this->paginate = [
55
            'maxLimit' => Configure::read('User.user_per_page')
56
        ];
57
        $users = $this->Users
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
58
            ->find()
59
            ->contain([
60
                'Groups'
61
            ])
62
            ->order([
63
                'Users.created' => 'desc'
64
            ]);
65
66
        $users = $this->paginate($users);
67
68
        $this->set(compact('users'));
69
    }
70
71
    /**
72
     * Login and register page.
73
     *
74
     * @return \Cake\Network\Response|void
75
     */
76
    public function login()
77
    {
78
        $userRegister = $this->Users->newEntity($this->request->data, ['validate' => 'create']);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
79
80
        if ($this->request->is('post')) {
81
            $method = ($this->request->data['method']) ? $this->request->data['method'] : false;
82
83
            switch ($method) {
84
                case "login":
85
                    $userLogin = $this->Auth->identify();
86
87
                    if ($userLogin) {
88
                        if ($userLogin['is_deleted'] == true) {
89
                            $this->Flash->error(__("This account has been deleted."));
90
91
                            break;
92
                        }
93
94
                        $this->Auth->setUser($userLogin);
0 ignored issues
show
Bug introduced by
It seems like $userLogin defined by $this->Auth->identify() on line 85 can also be of type boolean; however, Cake\Controller\Component\AuthComponent::setUser() does only seem to accept array|object<ArrayAccess>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
95
96
                        $user = $this->Users->newEntity($userLogin, ['accessibleFields' => ['id' => true]]);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
97
                        $user->isNew(false);
98
99
                        $user->last_login = new Time();
100
                        $user->last_login_ip = $this->request->clientIp();
101
102
                        $this->Users->save($user);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
103
104
                        //Cookies.
105
                        $this->Cookie->configKey('CookieAuth', [
106
                            'expires' => '+1 year',
107
                            'httpOnly' => true
108
                        ]);
109
                        $this->Cookie->write('CookieAuth', [
110
                            'username' => $this->request->data('username'),
111
                            'password' => $this->request->data('password')
112
                        ]);
113
114
                        //Badge Event.
115
                        $this->eventManager()->attach(new Badges($this));
0 ignored issues
show
Documentation introduced by
new \App\Event\Badges($this) is of type object<App\Event\Badges>, 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...
116
117
                        $user = new Event('Model.Users.register', $this, [
118
                            'user' => $user
119
                        ]);
120
                        $this->eventManager()->dispatch($user);
121
122
                        $url = $this->Auth->redirectUrl();
123 View Code Duplication
                        if (substr($this->Auth->redirectUrl(), -5) == 'login') {
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...
124
                            $url = ['controller' => 'pages', 'action' => 'home'];
125
                        }
126
127
                        return $this->redirect($url);
128
                    }
129
130
                    $this->Flash->error(__("Your username or password doesn't match."));
131
132
                    break;
133
134
                case "register":
135
                    $userRegister->register_ip = $this->request->clientIp();
136
                    $userRegister->last_login_ip = $this->request->clientIp();
137
                    $userRegister->last_login = new Time();
138
139
                    if ($this->Recaptcha->verify()) {
0 ignored issues
show
Documentation introduced by
The property Recaptcha does not exist on object<App\Controller\UsersController>. 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...
140
                        if ($this->Users->save($userRegister)) {
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
141
                            $user = $this->Auth->identify();
142
143
                            if ($user) {
144
                                $this->Auth->setUser($user);
0 ignored issues
show
Bug introduced by
It seems like $user defined by $this->Auth->identify() on line 141 can also be of type boolean; however, Cake\Controller\Component\AuthComponent::setUser() does only seem to accept array|object<ArrayAccess>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
145
                            }
146
147
                            $user = $this->Users->get($user['id']);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
148
149
                            //Statistics Event.
150
                            $this->eventManager()->attach(new Statistics());
0 ignored issues
show
Documentation introduced by
new \App\Event\Statistics() is of type object<App\Event\Statistics>, 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...
151
                            $stats = new Event('Model.Users.register', $this);
152
                            $this->eventManager()->dispatch($stats);
153
154
                            //Notification Events.
155
                            $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...
156
                            $event = new Event('Model.Notifications.new', $this, [
157
                                'user_id' => $user->id,
158
                                'type' => 'bot'
159
                            ]);
160
                            $this->eventManager()->dispatch($event);
161
162
                            $viewVars = [
163
                                'user' => $user,
164
                                'name' => $user->full_name
165
                            ];
166
167
                            $email = new Email();
168
                            $email->profile('default')
169
                                ->template('register', 'default')
170
                                ->emailFormat('html')
171
                                ->from(['[email protected]' => __d('mail', 'Welcome on {0} !', \Cake\Core\Configure::read('Site.name'))])
172
                                ->to($user->email)
173
                                ->subject(__d('mail', 'Welcome on {0} !', \Cake\Core\Configure::read('Site.name')))
174
                                ->viewVars($viewVars)
175
                                ->send();
176
177
                            $this->Flash->success(__("Your account has been created successfully !"));
178
179
                            $url = $this->Auth->redirectUrl();
180 View Code Duplication
                            if (substr($this->Auth->redirectUrl(), -5) == 'login') {
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...
181
                                $url = ['controller' => 'pages', 'action' => 'home'];
182
                            }
183
184
                            return $this->redirect($url);
185
                        }
186
187
                        $this->Flash->error(__("Please, correct your mistake."));
188
                    } else {
189
                        $this->Flash->error(__("Please, correct your Captcha."));
190
                    }
191
192
                    break;
193
            }
194
        } else {
195
            //Save the referer URL before the user send the login/register request else it will delete the referer.
196
            $this->request->session()->write('Auth.redirect', $this->referer());
197
        }
198
199
        if ($this->Auth->user()) {
200
            return $this->redirect($this->Auth->redirectUrl());
201
        }
202
203
        $this->set(compact('userRegister'));
204
    }
205
206
    /**
207
     * Logout an user.
208
     *
209
     * @return \Cake\Network\Response
210
     */
211
    public function logout()
212
    {
213
        return $this->redirect($this->Auth->logout());
214
    }
215
216
    /**
217
     * Page to configure our account.
218
     *
219
     * @return void
220
     */
221
    public function account()
222
    {
223
        $user = $this->Users->get($this->Auth->user('id'));
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
224
225
        if ($this->request->is('put')) {
226
            $user->accessible('avatar_file', true);
227
            $this->Users->patchEntity($user, $this->request->data(), ['validate' => 'account']);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
228
229
            if ($this->Users->save($user)) {
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
230
                $this->request->session()->write('Auth.User.avatar', $user->avatar);
231
                $this->Flash->success(__("Your information has been updated !"));
232
            }
233
        }
234
235
        $this->set(compact('user'));
236
    }
237
238
    /**
239
     * Page to configure our settings.
240
     *
241
     * @return \Cake\Network\Response|void
242
     */
243
    public function settings()
244
    {
245
        $user = $this->Users->get($this->Auth->user('id'));
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
246
247
        $oldEmail = $user->email;
248
249
        if ($this->request->is('put')) {
250
            $method = ($this->request->data['method']) ? $this->request->data['method'] : false;
251
252
            switch ($method) {
253
                case "email":
254
                    if (!isset($this->request->data['email'])) {
255
                        $this->set(compact('user', 'oldEmail'));
256
257
                        return $this->redirect(['action' => 'settings']);
258
                    }
259
260
                    $this->Users->patchEntity($user, $this->request->data(), ['validate' => 'settings']);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
261
262
                    if ($this->Users->save($user)) {
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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
                        $oldEmail = $this->request->data['email'];
264
265
                        $this->Flash->success(__("Your E-mail has been changed !"));
266
                    }
267
                    break;
268
269
                case "password":
270
                    $data = $this->request->data;
271
                    if (!isset($data['old_password']) || !isset($data['password']) || !isset($data['password_confirm'])) {
272
                        $this->set(compact('user', 'oldEmail'));
273
274
                        return $this->Flash->error(__("Please, complete all fields !"));
275
                    }
276
277
                    if (!(new DefaultPasswordHasher)->check($data['old_password'], $user->password)) {
278
                        $this->set(compact('user', 'oldEmail'));
279
280
                        return $this->Flash->error(__("Your old password don't match !"));
281
                    }
282
283
                    $this->Users->patchEntity($user, $this->request->data(), ['validate' => 'settings']);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
284
                    if ($this->Users->save($user)) {
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
285
                        $this->Flash->success(__("Your password has been changed !"));
286
                    }
287
                    break;
288
            }
289
        }
290
291
        $this->set(compact('user', 'oldEmail'));
292
    }
293
294
    /**
295
     * View a profile page of an user.
296
     *
297
     * @return \Cake\Network\Response|void
298
     */
299
    public function profile()
300
    {
301
        $user = $this->Users
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
302
            ->find()
303
            ->where([
304
                'Users.id' => $this->request->id
305
            ])
306
            ->contain([
307
                'Groups' => function ($q) {
308
                    return $q->find('translations')->select(['id', 'name', 'css', 'is_staff', 'is_member']);
309
                },
310
                'BlogArticles' => function ($q) {
311
                    return $q
312
                        ->find('translations')
313
                        ->limit(Configure::read('User.Profile.max_blog_articles'))
314
                        ->order(['BlogArticles.created' => 'DESC']);
315
                },
316
                'BlogArticlesComments' => function ($q) {
317
                    return $q
318
                        ->limit(Configure::read('User.Profile.max_blog_comments'))
319
                        ->contain([
320
                            'BlogArticles' => function ($q) {
321
                                return $q->select(['id', 'title']);
322
                            }
323
                        ])
324
                        ->order(['BlogArticlesComments.created' => 'DESC']);
325
                },
326
                'BadgesUsers' => function ($q) {
327
                    return $q
328
                        ->contain([
329
                            'Badges' => function ($q) {
330
                                return $q
331
                                    ->select([
332
                                        'name',
333
                                        'picture'
334
                                    ]);
335
                            }
336
                        ])
337
                        ->order([
338
                            'BadgesUsers.id' => 'DESC'
339
                        ]);
340
                }
341
            ])
342
            ->map(function ($user) {
343
                $user->online = $this->SessionsActivity->getOnlineStatus($user);
0 ignored issues
show
Documentation introduced by
The property SessionsActivity does not exist on object<App\Controller\UsersController>. 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...
344
                $user->background_profile = UsersUtility::getProfileBackground();
345
346
                return $user;
347
            })
348
            ->first();
349
350 View Code Duplication
        if (is_null($user) || $user->is_deleted == true) {
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...
351
            $this->Flash->error(__('This user doesn\'t exist or has been deleted.'));
352
353
            return $this->redirect(['controller' => 'pages', 'action' => 'home']);
354
        }
355
356
        $this->set(compact('user'));
357
    }
358
359
    /**
360
     * Delete an user with all his comments, articles and likes.
361
     *
362
     * @return \Cake\Network\Response
363
     */
364
    public function delete()
365
    {
366
        if (!$this->request->is('post')) {
367
            return $this->redirect(['action' => 'settings']);
368
        }
369
370
        $user = $this->Users->get($this->Auth->user('id'));
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
371
372
        if (!(new DefaultPasswordHasher)->check($this->request->data['password'], $user->password)) {
373
            $this->Flash->error(__("Your password doesn't match !"));
374
375
            return $this->redirect(['action' => 'settings']);
376
        }
377
378
        $user->is_deleted = true;
379
380
        if ($this->Users->save($user)) {
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
381
            $this->Flash->success(__("Your account has been deleted successfully ! Thanks for your visit !"));
382
383
            return $this->redirect($this->Auth->logout());
384
        }
385
386
        $this->Flash->error(__("Unable to delete your account, please try again."));
387
388
        return $this->redirect(['action' => 'settings']);
389
    }
390
391
    /**
392
     * Display all notifications related to the user.
393
     *
394
     * @return void
395
     */
396
    public function notifications()
397
    {
398
        $this->loadModel('Notifications');
399
400
        $this->paginate = [
401
            'maxLimit' => Configure::read('User.notifications_per_page')
402
        ];
403
404
        $notifications = $this->Notifications
0 ignored issues
show
Documentation introduced by
The property Notifications does not exist on object<App\Controller\UsersController>. 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...
405
            ->find()
406
            ->where([
407
                'user_id' => $this->Auth->user('id')
408
            ])
409
            ->order([
410
                'is_read' => 'ASC',
411
                'created' => 'DESC'
412
            ])
413
            ->find('map', [
414
                'session' => $this->request->session()
415
            ]);
416
417
        $notifications = $this->paginate($notifications);
418
419
        $this->set(compact('notifications'));
420
    }
421
422
    /**
423
     * Display the form to reset the password.
424
     *
425
     * @return \Cake\Network\Response|void
426
     */
427
    public function forgotPassword()
428
    {
429
        if ($this->Auth->user()) {
430
            return $this->redirect(['controller' => 'pages', 'action' => 'home']);
431
        }
432
433
        $user = $this->Users->newEntity($this->request->data);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
434
435
        if ($this->request->is('post')) {
436
            $user = $this->Users
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
437
                ->find()
438
                ->where([
439
                    'Users.email' => $this->request->data['email']
440
                ])
441
                ->first();
442
443
            if (is_null($user)) {
444
                $this->Flash->error(__("This E-mail doesn't exist or the account has been deleted."));
445
446
                $this->set(compact('user'));
447
448
                return;
449
            }
450
451
            if (!$this->Recaptcha->verify()) {
0 ignored issues
show
Documentation introduced by
The property Recaptcha does not exist on object<App\Controller\UsersController>. 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...
452
                $this->Flash->error(__("Please, correct your Captcha."));
453
454
                $this->set(compact('user'));
455
456
                return;
457
            }
458
459
            //Generate the unique code
460
            $code = md5(rand() . uniqid() . time());
461
462
            //Update the user's information
463
            $user->password_code = $code;
464
            $user->password_code_expire = new Time();
465
466
            $this->Users->save($user);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
467
468
            $viewVars = [
469
                'userId' => $user->id,
470
                'name' => $user->full_name,
471
                'username' => $user->username,
472
                'code' => $code
473
            ];
474
475
            $email = new Email();
476
            $email->profile('default')
477
                ->template('forgotPassword', 'default')
478
                ->emailFormat('html')
479
                ->from(['[email protected]' => __('Forgot your Password - Xeta')])
480
                ->to($user->email)
481
                ->subject(__('Forgot your Password - Xeta'))
482
                ->viewVars($viewVars)
483
                ->send();
484
485
            $this->Flash->success(__("An E-mail has been send to <strong>{0}</strong>. Please follow the instructions in the E-mail.", h($user->email)));
486
        }
487
488
        $this->set(compact('user'));
489
    }
490
491
    /**
492
     * Display the form to reset his password.
493
     *
494
     * @return \Cake\Network\Response|void
495
     */
496
    public function resetPassword()
497
    {
498
        if ($this->Auth->user()) {
499
            return $this->redirect(['controller' => 'pages', 'action' => 'home']);
500
        }
501
502
        //Prevent for empty code.
503
        if (empty(trim($this->request->code))) {
504
            $this->Flash->error(__("This code is not associated with this users or is incorrect."));
505
506
            return $this->redirect(['controller' => 'pages', 'action' => 'home']);
507
        }
508
509
        $user = $this->Users
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
510
            ->find()
511
            ->where([
512
                'Users.password_code' => $this->request->code,
513
                'Users.id' => $this->request->id
514
            ])
515
            ->first();
516
517 View Code Duplication
        if (is_null($user)) {
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...
518
            $this->Flash->error(__("This code is not associated with this users or is incorrect."));
519
520
            return $this->redirect(['controller' => 'pages', 'action' => 'home']);
521
        }
522
523
        $expire = $user->password_code_expire->timestamp + (Configure::read('User.ResetPassword.expire_code') * 60);
524
525
        if ($expire < time()) {
526
            $this->Flash->error(__("This code is expired, please ask another E-mail code."));
527
528
            return $this->redirect(['action' => 'forgotPassword']);
529
        }
530
531
        if ($this->request->is(['post', 'put'])) {
532
            $this->Users->patchEntity($user, $this->request->data, ['validate' => 'resetpassword']);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
533
534
            if ($this->Users->save($user)) {
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
535
                $this->Flash->success(__("Your password has been changed !"));
536
537
                //Reset the code and the time.
538
                $user->password_code = '';
539
                $user->password_code_expire = new Time();
540
                $user->password_reset_count = $user->password_reset_count + 1;
541
                $this->Users->save($user);
0 ignored issues
show
Documentation introduced by
The property Users does not exist on object<App\Controller\UsersController>. 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...
542
543
                return $this->redirect(['controller' => 'users', 'action' => 'login']);
544
            }
545
        }
546
547
        $this->set(compact('user'));
548
    }
549
}
550