Completed
Push — master ( 75fca3...057bf7 )
by Fèvre
22s queued 10s
created

UsersController   D

Complexity

Total Complexity 54

Size/Duplication

Total Lines 520
Duplicated Lines 7.88 %

Coupling/Cohesion

Components 1
Dependencies 17

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 54
c 3
b 1
f 0
lcom 1
cbo 17
dl 41
loc 520
rs 4.1547

10 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 10 3
A beforeFilter() 0 6 1
D login() 6 121 13
A logout() 0 4 1
C settings() 0 50 12
A profile() 5 58 3
B forgotPassword() 0 55 5
B resetPassword() 5 53 7
A account() 0 16 3
B notifications() 25 25 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 UsersController 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 UsersController, and based on these observations, apply Extract Interface, too.

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\Mailer\MailerAwareTrait;
13
14
class UsersController extends AppController
15
{
16
    use MailerAwareTrait;
17
18
    /**
19
     * Initialize handle.
20
     *
21
     * @return void
22
     */
23
    public function initialize()
24
    {
25
        parent::initialize();
26
27
        $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...
28
29
        if ($action === 'login' || $action === 'forgotPassword') {
30
            $this->loadComponent('Recaptcha.Recaptcha');
31
        }
32
    }
33
34
    /**
35
     * BeforeFilter handle.
36
     *
37
     * @param Event $event The beforeFilter event that was fired.
38
     *
39
     * @return void
40
     */
41
    public function beforeFilter(Event $event)
42
    {
43
        parent::beforeFilter($event);
44
45
        $this->Auth->allow(['index', 'logout', 'profile', 'forgotPassword', 'resetPassword']);
46
    }
47
48
    /**
49
     * Display all Users.
50
     *
51
     * @return void
52
     */
53
    public function index()
54
    {
55
        $this->paginate = [
56
            'maxLimit' => Configure::read('User.user_per_page')
57
        ];
58
        $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...
59
            ->find()
60
            ->contain([
61
                'Groups'
62
            ])
63
            ->order([
64
                'Users.created' => 'desc'
65
            ]);
66
67
        $users = $this->paginate($users);
68
69
        $this->set(compact('users'));
70
    }
71
72
    /**
73
     * Login and register page.
74
     *
75
     * @return \Cake\Network\Response|void
76
     */
77
    public function login()
78
    {
79
        $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...
80
81
        if ($this->request->is('post')) {
82
            $method = ($this->request->data['method']) ? $this->request->data['method'] : false;
83
84
            switch ($method) {
85
                case "login":
86
                    $userLogin = $this->Auth->identify();
87
88
                    if ($userLogin) {
89
                        if ($userLogin['is_deleted'] == true) {
90
                            $this->Flash->error(__("This account has been deleted."));
91
92
                            break;
93
                        }
94
95
                        $this->Auth->setUser($userLogin);
0 ignored issues
show
Bug introduced by
It seems like $userLogin defined by $this->Auth->identify() on line 86 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...
96
97
                        $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...
98
                        $user->isNew(false);
99
100
                        $user->last_login = new Time();
101
                        $user->last_login_ip = $this->request->clientIp();
102
103
                        $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...
104
105
                        //Cookies.
106
                        $this->Cookie->configKey('CookieAuth', [
107
                            'expires' => '+1 year',
108
                            'httpOnly' => true
109
                        ]);
110
                        $this->Cookie->write('CookieAuth', [
111
                            'username' => $this->request->data('username'),
112
                            'password' => $this->request->data('password')
113
                        ]);
114
115
                        //Badge Event.
116
                        $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...
117
118
                        $user = new Event('Model.Users.register', $this, [
119
                            'user' => $user
120
                        ]);
121
                        $this->eventManager()->dispatch($user);
122
123
                        $url = $this->Auth->redirectUrl();
124 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...
125
                            $url = ['controller' => 'pages', 'action' => 'home'];
126
                        }
127
128
                        return $this->redirect($url);
129
                    }
130
131
                    $this->Flash->error(__("Your username or password doesn't match."));
132
133
                    break;
134
135
                case "register":
136
                    $userRegister->register_ip = $this->request->clientIp();
137
                    $userRegister->last_login_ip = $this->request->clientIp();
138
                    $userRegister->last_login = new Time();
139
140
                    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...
141
                        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...
142
                            $user = $this->Auth->identify();
143
144
                            if ($user) {
145
                                $this->Auth->setUser($user);
0 ignored issues
show
Bug introduced by
It seems like $user defined by $this->Auth->identify() on line 142 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...
146
                            }
147
148
                            $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...
149
150
                            //Statistics Event.
151
                            $this->eventManager()->attach(new Statistics());
0 ignored issues
show
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...
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...
152
                            $stats = new Event('Model.Users.register', $this);
153
                            $this->eventManager()->dispatch($stats);
154
155
                            //Notification Events.
156
                            $this->eventManager()->attach(new Notifications());
0 ignored issues
show
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...
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...
157
                            $event = new Event('Model.Notifications.new', $this, [
158
                                'user_id' => $user->id,
159
                                'type' => 'bot'
160
                            ]);
161
                            $this->eventManager()->dispatch($event);
162
163
                            $viewVars = [
164
                                'user' => $user,
165
                                'name' => $user->full_name
166
                            ];
167
168
                            $this->getMailer('User')->send('register', [$user, $viewVars]);
169
170
                            $this->Flash->success(__("Your account has been created successfully !"));
171
172
                            $url = $this->Auth->redirectUrl();
173 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...
174
                                $url = ['controller' => 'pages', 'action' => 'home'];
175
                            }
176
177
                            return $this->redirect($url);
178
                        }
179
180
                        $this->Flash->error(__("Please, correct your mistake."));
181
                    } else {
182
                        $this->Flash->error(__("Please, correct your Captcha."));
183
                    }
184
185
                    break;
186
            }
187
        } else {
188
            //Save the referer URL before the user send the login/register request else it will delete the referer.
189
            $this->request->session()->write('Auth.redirect', $this->referer());
190
        }
191
192
        if ($this->Auth->user()) {
193
            return $this->redirect($this->Auth->redirectUrl());
194
        }
195
196
        $this->set(compact('userRegister'));
197
    }
198
199
    /**
200
     * Logout an user.
201
     *
202
     * @return \Cake\Network\Response
203
     */
204
    public function logout()
205
    {
206
        return $this->redirect($this->Auth->logout());
207
    }
208
209
    /**
210
     * Page to configure our account.
211
     *
212
     * @return void
213
     */
214
    public function account()
215
    {
216
        $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...
217
218
        if ($this->request->is('put')) {
219
            $user->accessible('avatar_file', true);
220
            $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...
221
222
            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...
223
                $this->request->session()->write('Auth.User.avatar', $user->avatar);
224
                $this->Flash->success(__("Your information has been updated !"));
225
            }
226
        }
227
228
        $this->set(compact('user'));
229
    }
230
231
    /**
232
     * Page to configure our settings.
233
     *
234
     * @return \Cake\Network\Response|void
235
     */
236
    public function settings()
237
    {
238
        $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...
239
240
        $oldEmail = $user->email;
241
242
        if ($this->request->is('put')) {
243
            $method = ($this->request->data['method']) ? $this->request->data['method'] : false;
244
245
            switch ($method) {
246
                case "email":
247
                    if (!isset($this->request->data['email'])) {
248
                        $this->set(compact('user', 'oldEmail'));
249
250
                        return $this->redirect(['action' => 'settings']);
251
                    }
252
253
                    $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...
254
255
                    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...
256
                        $oldEmail = $this->request->data['email'];
257
258
                        $this->Flash->success(__("Your E-mail has been changed !"));
259
                    }
260
                    break;
261
262
                case "password":
263
                    $data = $this->request->data;
264
                    if (!isset($data['old_password']) || !isset($data['password']) || !isset($data['password_confirm'])) {
265
                        $this->set(compact('user', 'oldEmail'));
266
267
                        return $this->Flash->error(__("Please, complete all fields !"));
268
                    }
269
270
                    if (!(new DefaultPasswordHasher)->check($data['old_password'], $user->password)) {
271
                        $this->set(compact('user', 'oldEmail'));
272
273
                        return $this->Flash->error(__("Your old password don't match !"));
274
                    }
275
276
                    $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...
277
                    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...
278
                        $this->Flash->success(__("Your password has been changed !"));
279
                    }
280
                    break;
281
            }
282
        }
283
284
        $this->set(compact('user', 'oldEmail'));
285
    }
286
287
    /**
288
     * View a profile page of an user.
289
     *
290
     * @return \Cake\Network\Response|void
291
     */
292
    public function profile()
293
    {
294
        $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...
295
            ->find()
296
            ->where([
297
                'Users.id' => $this->request->id
298
            ])
299
            ->contain([
300
                'Groups' => function ($q) {
301
                    return $q->select(['id', 'name', 'css', 'is_staff', 'is_member']);
302
                },
303
                'BlogArticles' => function ($q) {
304
                    return $q
305
                        ->limit(Configure::read('User.Profile.max_blog_articles'))
306
                        ->order(['BlogArticles.created' => 'DESC']);
307
                },
308
                'BlogArticlesComments' => function ($q) {
309
                    return $q
310
                        ->limit(Configure::read('User.Profile.max_blog_comments'))
311
                        ->contain([
312
                            'BlogArticles' => function ($q) {
313
                                return $q->select(['id', 'title']);
314
                            }
315
                        ])
316
                        ->order(['BlogArticlesComments.created' => 'DESC']);
317
                },
318
                'BadgesUsers' => function ($q) {
319
                    return $q
320
                        ->contain([
321
                            'Badges' => function ($q) {
322
                                return $q
323
                                    ->select([
324
                                        'name',
325
                                        'picture'
326
                                    ]);
327
                            }
328
                        ])
329
                        ->order([
330
                            'BadgesUsers.id' => 'DESC'
331
                        ]);
332
                }
333
            ])
334
            ->map(function ($user) {
335
                $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...
336
                $user->background_profile = UsersUtility::getProfileBackground();
337
338
                return $user;
339
            })
340
            ->first();
341
342 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...
343
            $this->Flash->error(__('This user doesn\'t exist or has been deleted.'));
344
345
            return $this->redirect(['controller' => 'pages', 'action' => 'home']);
346
        }
347
348
        $this->set(compact('user'));
349
    }
350
351
    /**
352
     * Delete an user with all his comments, articles and likes.
353
     *
354
     * @return \Cake\Network\Response
355
     */
356
    public function delete()
357
    {
358
        if (!$this->request->is('post')) {
359
            return $this->redirect(['action' => 'settings']);
360
        }
361
362
        $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...
363
364
        if (!(new DefaultPasswordHasher)->check($this->request->data['password'], $user->password)) {
365
            $this->Flash->error(__("Your password doesn't match !"));
366
367
            return $this->redirect(['action' => 'settings']);
368
        }
369
370
        $user->is_deleted = true;
371
372
        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...
373
            $this->Flash->success(__("Your account has been deleted successfully ! Thanks for your visit !"));
374
375
            return $this->redirect($this->Auth->logout());
376
        }
377
378
        $this->Flash->error(__("Unable to delete your account, please try again."));
379
380
        return $this->redirect(['action' => 'settings']);
381
    }
382
383
    /**
384
     * Display all notifications related to the user.
385
     *
386
     * @return void
387
     */
388 View Code Duplication
    public function notifications()
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...
389
    {
390
        $this->loadModel('Notifications');
391
392
        $this->paginate = [
393
            'maxLimit' => Configure::read('User.notifications_per_page')
394
        ];
395
396
        $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...
397
            ->find()
398
            ->where([
399
                'user_id' => $this->Auth->user('id')
400
            ])
401
            ->order([
402
                'is_read' => 'ASC',
403
                'created' => 'DESC'
404
            ])
405
            ->find('map', [
406
                'session' => $this->request->session()
407
            ]);
408
409
        $notifications = $this->paginate($notifications);
410
411
        $this->set(compact('notifications'));
412
    }
413
414
    /**
415
     * Display the form to reset the password.
416
     *
417
     * @return \Cake\Network\Response|void
418
     */
419
    public function forgotPassword()
420
    {
421
        if ($this->Auth->user()) {
422
            return $this->redirect(['controller' => 'pages', 'action' => 'home']);
423
        }
424
425
        $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...
426
427
        if ($this->request->is('post')) {
428
            $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...
429
                ->find()
430
                ->where([
431
                    'Users.email' => $this->request->data['email']
432
                ])
433
                ->first();
434
435
            if (is_null($user)) {
436
                $this->Flash->error(__("This E-mail doesn't exist or the account has been deleted."));
437
438
                $this->set(compact('user'));
439
440
                return;
441
            }
442
443
            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...
444
                $this->Flash->error(__("Please, correct your Captcha."));
445
446
                $this->set(compact('user'));
447
448
                return;
449
            }
450
451
            //Generate the unique code
452
            $code = md5(rand() . uniqid() . time());
453
454
            //Update the user's information
455
            $user->password_code = $code;
456
            $user->password_code_expire = new Time();
457
458
            $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...
459
460
            $viewVars = [
461
                'userId' => $user->id,
462
                'name' => $user->full_name,
463
                'username' => $user->username,
464
                'code' => $code
465
            ];
466
467
            $this->getMailer('User')->send('forgotPassword', [$user, $viewVars]);
468
469
            $this->Flash->success(__("An E-mail has been send to <strong>{0}</strong>. Please follow the instructions in the E-mail.", h($user->email)));
470
        }
471
472
        $this->set(compact('user'));
473
    }
474
475
    /**
476
     * Display the form to reset his password.
477
     *
478
     * @return \Cake\Network\Response|void
479
     */
480
    public function resetPassword()
481
    {
482
        if ($this->Auth->user()) {
483
            return $this->redirect(['controller' => 'pages', 'action' => 'home']);
484
        }
485
486
        //Prevent for empty code.
487
        if (empty(trim($this->request->code))) {
488
            $this->Flash->error(__("This code is not associated with this users or is incorrect."));
489
490
            return $this->redirect(['controller' => 'pages', 'action' => 'home']);
491
        }
492
493
        $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...
494
            ->find()
495
            ->where([
496
                'Users.password_code' => $this->request->code,
497
                'Users.id' => $this->request->id
498
            ])
499
            ->first();
500
501 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...
502
            $this->Flash->error(__("This code is not associated with this users or is incorrect."));
503
504
            return $this->redirect(['controller' => 'pages', 'action' => 'home']);
505
        }
506
507
        $expire = $user->password_code_expire->timestamp + (Configure::read('User.ResetPassword.expire_code') * 60);
508
509
        if ($expire < time()) {
510
            $this->Flash->error(__("This code is expired, please ask another E-mail code."));
511
512
            return $this->redirect(['action' => 'forgotPassword']);
513
        }
514
515
        if ($this->request->is(['post', 'put'])) {
516
            $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...
517
518
            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...
519
                $this->Flash->success(__("Your password has been changed !"));
520
521
                //Reset the code and the time.
522
                $user->password_code = '';
523
                $user->password_code_expire = new Time();
524
                $user->password_reset_count = $user->password_reset_count + 1;
525
                $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...
526
527
                return $this->redirect(['controller' => 'users', 'action' => 'login']);
528
            }
529
        }
530
531
        $this->set(compact('user'));
532
    }
533
}
534