Completed
Pull Request — master (#18)
by
unknown
04:15
created

UsersController   A

Complexity

Total Complexity 33

Size/Duplication

Total Lines 451
Duplicated Lines 31.04 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 5
Bugs 1 Features 2
Metric Value
wmc 33
lcom 1
cbo 3
dl 140
loc 451
rs 9.3999
c 5
b 1
f 2

24 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 5 1
A setupAction() 0 5 1
A listAction() 10 10 1
A acronymAction() 10 10 1
A idAction() 9 9 1
A add1Action() 0 21 2
A addAction() 0 11 1
B createAddUserForm() 0 30 1
B callbackSubmitAddUser() 0 29 2
A callbackSubmitFailAddUser() 0 5 1
A callbackSuccess() 0 5 1
A callbackFail() 0 5 1
A updateAction() 19 19 2
B createUpdateUserForm() 0 37 1
B callbackSubmitUpdateUser() 0 32 2
A callbackSubmitFailUpdateUser() 0 5 1
A deleteAction() 0 10 2
A softDeleteAction() 15 15 2
A undoDeleteAction() 13 13 2
A activateAction() 13 13 2
A deactivateAction() 13 13 2
A activeAction() 13 13 1
A inactiveAction() 13 13 1
A wastebasketAction() 12 12 1

How to fix   Duplicated Code   

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:

1
<?php
2
3
namespace Anax\Users;
4
5
/**
6
 * A controller for users and admin related events.
7
 *
8
 */
9
class UsersController implements \Anax\DI\IInjectionAware
10
{
11
    use \Anax\DI\TInjectable,
12
    \Anax\MVC\TRedirectHelpers;
13
14
    /**
15
     * Initialize the controller.
16
     *
17
     * @return void
18
     */
19
    public function initialize()
20
    {
21
        $this->users = new \Anax\Users\User();
0 ignored issues
show
Bug introduced by
The property users does not exist. Did you maybe forget to declare it?

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22
        $this->users->setDI($this->di);
0 ignored issues
show
Bug introduced by
It seems like $this->di can also be of type array or null; however, Anax\DI\TInjectable::setDI() does only seem to accept object<Anax\DI\class>, 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...
23
    }
24
25
    /**
26
     * Setup initial table for users.
27
     *
28
     * @return void
29
     */
30
    public function setupAction()
31
    {
32
        $this->users->init();
33
        $this->redirectTo('users/list/');
34
    }
35
    /**
36
     * List all users.
37
     *
38
     * @return void
39
     */
40 View Code Duplication
    public function listAction()
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...
41
    {
42
        $all = $this->users->findAll();
43
44
        $this->theme->setTitle("List all users");
0 ignored issues
show
Documentation introduced by
The property theme does not exist on object<Anax\Users\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...
45
        $this->views->add('users/list-all', [
0 ignored issues
show
Documentation introduced by
The property views does not exist on object<Anax\Users\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...
46
            'users' => $all,
47
            'title' => "View all users",
48
        ]);
49
    }
50
    /**
51
     * List user with acronym.
52
     *
53
     * @param int $id of user to display
0 ignored issues
show
Bug introduced by
There is no parameter named $id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
54
     *
55
     * @return void
56
     */
57 View Code Duplication
    public function acronymAction($acronym = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
58
    {
59
        $user = $this->users->query()
60
        ->where('acronym = ' . "'$acronym'")
61
        ->execute()[0];
62
        $this->theme->setTitle("View user with acronym");
0 ignored issues
show
Documentation introduced by
The property theme does not exist on object<Anax\Users\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...
63
        $this->views->add('users/view', [
0 ignored issues
show
Documentation introduced by
The property views does not exist on object<Anax\Users\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...
64
            'user' => $user,
65
        ]);
66
    }
67
    /**
68
     * List user with id.
69
     *
70
     * @param int $id of user to display
71
     *
72
     * @return void
73
     */
74 View Code Duplication
    public function idAction($id = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
75
    {
76
        $user = $this->users->find($id);
77
78
        $this->theme->setTitle("View user with id");
0 ignored issues
show
Documentation introduced by
The property theme does not exist on object<Anax\Users\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
        $this->views->add('users/view', [
0 ignored issues
show
Documentation introduced by
The property views does not exist on object<Anax\Users\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
            'user' => $user,
81
        ]);
82
    }
83
    /**
84
     * Add new user.
85
     *
86
     * @param string $acronym of user to add.
87
     *
88
     * @return void
89
     */
90
    public function add1Action($acronym = null)
91
    {
92
        if (!isset($acronym)) {
93
            die("Missing acronym");
94
        }
95
96
        $now = gmdate('Y-m-d H:i:s');
97
98
        $this->users->save([
99
            'acronym' => $acronym,
100
            'email' => $acronym . '@mail.se',
101
            'name' => 'Mr/Mrs ' . $acronym,
102
            'password' => password_hash($acronym, PASSWORD_DEFAULT),
103
            'created' => $now,
104
            'active' => $now,
105
        ]);
106
107
        // $url = $this->url->create('users/id/' . $this->users->id);
108
        // $this->response->redirect($url);
109
        $this->redirectTo('users/id/' . $this->users->id);
110
    }
111
    /**
112
     * Add new user.
113
     *
114
     * @param string $acronym of user to add.
115
     *
116
     * @return void
117
     */
118
    public function addAction($acronym = null)
0 ignored issues
show
Unused Code introduced by
The parameter $acronym is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
119
    {
120
        $this->di->session(); // Will load the session service which also starts the session
121
        $form = $this->createAddUserForm();
122
        $form->check([$this, 'callbackSuccess'], [$this, 'callbackFail']);
123
        $this->di->theme->setTitle("Add user");
124
        $this->di->views->add('default/page', [
125
            'title' => "Add user",
126
            'content' => $form->getHTML()
127
        ]);
128
    }
129
    private function createAddUserForm()
130
    {
131
        return $this->di->form->create([], [
132
            'name' => [
133
                'type'        => 'text',
134
                'label'       => 'Name of person:',
135
                'required'    => true,
136
                'validation'  => ['not_empty'],
137
            ],
138
            'acronym' => [
139
                'type'        => 'text',
140
                'label'       => 'Acronym of person:',
141
                'required'    => true,
142
                'validation'  => ['not_empty'],
143
            ],
144
            'email' => [
145
                'type'        => 'text',
146
                'required'    => true,
147
                'validation'  => ['not_empty', 'email_adress'],
148
            ],
149
            'submit' => [
150
                'type'      => 'submit',
151
                'callback'  => [$this, 'callbackSubmitAddUser'],
152
            ],
153
            'submit-fail' => [
154
                'type'      => 'submit',
155
                'callback'  => [$this, 'callbackSubmitFailAddUser'],
156
            ],
157
        ]);
158
    }
159
    /**
160
     * Callback for submit-button.
161
     *
162
     */
163
    public function callbackSubmitAddUser($form)
164
    {
165
        // $form->AddOutput("<p>DoSubmit(): Form was submitted.<p>");
166
        // $form->AddOutput("<p>Do stuff (save to database) and return true (success) or false (failed processing)</p>");
167
        $acronym = $form->Value('acronym');
168
        // Check for duplicate acronym. Die if exists.
169
        $all = $this->users->query()
170
            ->where("acronym = '$acronym'")
171
            ->execute();
172
        if (count($all)!=0) {
173
            die("User with acronym $acronym already in model.");
174
        }
175
        // Save user data to database
176
        $now = gmdate('Y-m-d H:i:s');
177
        $this->users->save([
178
            'acronym' => $form->Value('acronym'),
179
            'email' => $form->Value('email'),
180
            'name' => 'Mr/Mrs ' . $form->Value('name'),
181
            'password' => password_hash($acronym, PASSWORD_DEFAULT),
182
            'created' => $now,
183
            'active' => $now,
184
        ]);
185
186
        // $form->AddOutput("<p><b>Name: " . $form->Value('name') . "</b></p>");
187
        // $form->AddOutput("<p><b>Email: " . $form->Value('email') . "</b></p>");
188
        // $form->AddOutput("<p><b>Acronym: " . $form->Value('acronym') . "</b></p>");
189
        $form->saveInSession = false;
190
        return true;
191
    }
192
    /**
193
     * Callback for submit-button.
194
     *
195
     */
196
    public function callbackSubmitFailAddUser($form)
197
    {
198
        $form->AddOutput("<p><i>DoSubmitFail(): Form was submitted but I failed to process/save/validate it</i></p>");
199
        return false;
200
    }
201
    /**
202
     * Callback What to do if the form was submitted?
203
     *
204
     */
205
    public function callbackSuccess($form)
206
    {
207
        $form->AddOUtput("<p><i>Form was submitted and the callback method returned true.</i></p>");
208
        $this->redirectTo('users/id/' . $this->users->id);
209
    }
210
    /**
211
     * Callback What to do when form could not be processed?
212
     *
213
     */
214
    public function callbackFail($form)
215
    {
216
        $form->AddOutput("<p><i>Form was submitted and the Check() method returned false.</i></p>");
217
        $this->redirectTo();
218
    }
219
220
221
    /**
222
     * Update user.
223
     *
224
     * @param string $acronym of user to update.
0 ignored issues
show
Bug introduced by
There is no parameter named $acronym. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
225
     *
226
     * @return void
227
     */
228 View Code Duplication
    public function updateAction($id = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
229
    {
230
        $this->di->session(); // Will load the session service which also starts the session
231
        // Check if valid entry exists.
232
        $all = $this->users->query()
233
            ->where("id = '$id'")
234
            ->execute();
235
        if (count($all)!=1) {
236
            die("User with id $id not found.");
237
        }
238
        $user = $this->users->find($id);
239
        $form = $this->createUpdateUserForm($user);
240
        $form->check([$this, 'callbackSuccess'], [$this, 'callbackFail']);
241
        $this->di->theme->setTitle("Update user");
242
        $this->di->views->add('default/page', [
243
            'title' => "Update user",
244
            'content' => $form->getHTML()
245
        ]);
246
    }
247
    private function createUpdateUserForm($user = null)
248
    {
249
        return $this->di->form->create([], [
250
            'name' => [
251
                'type'        => 'text',
252
                'value'       => $user->name,
253
                'label'       => 'Name of person:',
254
                'required'    => true,
255
                'validation'  => ['not_empty'],
256
            ],
257
            'acronym' => [
258
                'type'        => 'text',
259
                'value'       => $user->acronym,
260
                'label'       => 'Acronym of person:',
261
                'required'    => true,
262
                'validation'  => ['not_empty'],
263
            ],
264
            'email' => [
265
                'type'        => 'text',
266
                'value'       => $user->email,
267
                'required'    => true,
268
                'validation'  => ['not_empty', 'email_adress'],
269
            ],
270
            'id' => [
271
                'type'        => 'hidden',
272
                'value'       => $user->id,
273
            ],
274
            'submit' => [
275
                'type'      => 'submit',
276
                'callback'  => [$this, 'callbackSubmitUpdateUser'],
277
            ],
278
            'submit-fail' => [
279
                'type'      => 'submit',
280
                'callback'  => [$this, 'callbackSubmitFailUpdateUser'],
281
            ],
282
        ]);
283
    }
284
    public function callbackSubmitUpdateUser($form)
285
    {
286
        // $form->AddOutput("<p>DoSubmit(): Form was submitted.<p>");
287
        // $form->AddOutput("<p>Do stuff (save to database) and return true (success) or false (failed processing)</p>");
288
        // Handle update to duplicate acronym. Die if other user already has acronym.
289
        $id = $form->Value('id');
290
        $acronym = $form->Value('acronym');
291
        $all = $this->users->query()
292
            ->where("id != '$id'")
293
            ->andwhere("acronym = '$acronym'")
294
            ->execute();
295
        if (count($all)==1) {
296
            die("User with acronym $acronym alredy defined for other user. ");
297
        }
298
        // die();
299
        // Save user data to database
300
        $now = gmdate('Y-m-d H:i:s');
0 ignored issues
show
Unused Code introduced by
$now is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
301
        $this->users->save([
302
            'acronym' => $form->Value('acronym'),
303
            'email' => $form->Value('email'),
304
            'name' => 'Mr/Mrs ' . $form->Value('name'),
305
            // 'password' => password_hash($acronym, PASSWORD_DEFAULT),
306
            // 'created' => $now,
307
            // 'active' => $now,
308
        ]);
309
310
        // $form->AddOutput("<p><b>Name: " . $form->Value('name') . "</b></p>");
311
        // $form->AddOutput("<p><b>Email: " . $form->Value('email') . "</b></p>");
312
        // $form->AddOutput("<p><b>Phone: " . $form->Value('acronym') . "</b></p>");
313
        $form->saveInSession = false;
314
        return true;
315
    }
316
    /**
317
     * Callback for submit-button.
318
     *
319
     */
320
    public function callbackSubmitFailUpdateUser($form)
321
    {
322
        $form->AddOutput("<p><i>DoSubmitFail(): Form was submitted but I failed to process/save/validate it</i></p>");
323
        return false;
324
    }
325
326
327
328
    /**
329
     * Delete user.
330
     *
331
     * @param integer $id of user to delete.
332
     *
333
     * @return void
334
     */
335
    public function deleteAction($id = null)
336
    {
337
        if (!isset($id)) {
338
            die("Missing id");
339
        }
340
341
        $res = $this->users->delete($id);
0 ignored issues
show
Unused Code introduced by
$res is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
342
343
        $this->redirectTo('users/list/');
344
    }
345
    /**
346
     * Delete (soft) user.
347
     *
348
     * @param integer $id of user to delete.
349
     *
350
     * @return void
351
     */
352 View Code Duplication
    public function softDeleteAction($id = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
353
    {
354
        if (!isset($id)) {
355
            die("Missing id");
356
        }
357
358
        $now = gmdate('Y-m-d H:i:s');
359
360
        $user = $this->users->find($id);
361
362
        $user->deleted = $now;
363
        $user->save();
364
365
        $this->redirectTo('users/list/');
366
    }
367 View Code Duplication
    public function undoDeleteAction($id = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
368
    {
369
        if (!isset($id)) {
370
            die("Missing id");
371
        }
372
373
        $user = $this->users->find($id);
374
375
        $user->deleted = null;
376
        $user->save();
377
378
        $this->redirectTo('users/id/' . $id);
379
    }
380 View Code Duplication
    public function activateAction($id = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
381
    {
382
        if (!isset($id)) {
383
            die("Missing id");
384
        }
385
386
        $user = $this->users->find($id);
387
388
        $user->active = gmdate('Y-m-d H:i:s');
389
        $user->save();
390
391
        $this->redirectTo('users/id/' . $id);
392
    }
393 View Code Duplication
    public function deactivateAction($id = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
394
    {
395
        if (!isset($id)) {
396
            die("Missing id");
397
        }
398
399
        $user = $this->users->find($id);
400
401
        $user->active = null;
402
        $user->save();
403
404
        $this->redirectTo('users/id/' . $id);
405
    }
406
    /**
407
     * List all active and not deleted users.
408
     *
409
     * @return void
410
     */
411 View Code Duplication
    public function activeAction()
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...
412
    {
413
        $all = $this->users->query()
414
            ->where('active IS NOT NULL')
415
            ->andWhere('deleted is NULL')
416
            ->execute();
417
418
        $this->theme->setTitle("Users that are active");
0 ignored issues
show
Documentation introduced by
The property theme does not exist on object<Anax\Users\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...
419
        $this->views->add('users/list-all', [
0 ignored issues
show
Documentation introduced by
The property views does not exist on object<Anax\Users\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...
420
            'users' => $all,
421
            'title' => "Users that are active",
422
        ]);
423
    }
424
    /**
425
     * List all inactive and not deleted users.
426
     *
427
     * @return void
428
     */
429 View Code Duplication
    public function inactiveAction()
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...
430
    {
431
        $all = $this->users->query()
432
            ->where('active IS NULL')
433
            ->andWhere('deleted is NULL')
434
            ->execute();
435
436
        $this->theme->setTitle("Users that are inactive");
0 ignored issues
show
Documentation introduced by
The property theme does not exist on object<Anax\Users\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
        $this->views->add('users/list-all', [
0 ignored issues
show
Documentation introduced by
The property views does not exist on object<Anax\Users\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...
438
            'users' => $all,
439
            'title' => "Users that are inactive",
440
        ]);
441
    }
442
    /**
443
     * List all active and not deleted users.
444
     *
445
     * @return void
446
     */
447 View Code Duplication
    public function wastebasketAction()
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...
448
    {
449
        $all = $this->users->query()
450
            ->where('deleted is NOT NULL')
451
            ->execute();
452
453
        $this->theme->setTitle("Users that are in wastebasket");
0 ignored issues
show
Documentation introduced by
The property theme does not exist on object<Anax\Users\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...
454
        $this->views->add('users/list-all', [
0 ignored issues
show
Documentation introduced by
The property views does not exist on object<Anax\Users\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...
455
            'users' => $all,
456
            'title' => "Users that are in wastebasket",
457
        ]);
458
    }
459
}
460