Completed
Pull Request — master (#20)
by Fredrik
03:15
created

UsersController   C

Complexity

Total Complexity 55

Size/Duplication

Total Lines 745
Duplicated Lines 25.64 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 16
Bugs 5 Features 6
Metric Value
wmc 55
c 16
b 5
f 6
lcom 1
cbo 6
dl 191
loc 745
rs 5

35 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 11 1
A setupAction() 0 4 1
A profidAction() 0 11 1
B mostactiveAction() 0 32 5
A profileAction() 0 62 3
B listAction() 0 34 3
A listadminAction() 10 10 1
A acronymAction() 10 10 1
A idAction() 9 9 1
A cardAction() 0 16 1
A addAction() 15 15 2
B createAddUserForm() 30 30 1
B callbackSubmitAddUser() 0 30 2
A callbackSubmitFailAddUser() 0 5 1
A callbackSuccess() 0 5 1
A callbackFail() 0 5 1
B updateAction() 0 25 3
B createUpdateUserForm() 0 38 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
A logoutAction() 0 5 1
A loginAction() 0 13 1
B createLoginForm() 25 25 1
B callbackSubmitLogin() 0 24 3
A callbackSubmitFailLogin() 0 6 1
A callbackLoginSuccess() 0 6 1
A callbackLoginFail() 0 6 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
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
        $this->questions = new \Anax\Questions\CQuestions();
0 ignored issues
show
Bug introduced by
The property questions 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...
24
        $this->questions->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...
25
        $this->answers = new \Anax\Answers\CAnswers();
0 ignored issues
show
Bug introduced by
The property answers 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...
26
        $this->answers->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...
27
        $this->comments = new \Anax\CommentDb\CommentsInDb();
0 ignored issues
show
Bug introduced by
The property comments 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...
28
        $this->comments->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...
29
    }
30
31
    /**
32
     * Setup initial table for users.
33
     *
34
     * @return void
35
     */
36
    public function setupAction()
37
    {
38
        $this->users->init();
39
    }
40
    /**
41
     * Display user with id.
42
     *
43
     * @param int $id of user to display
44
     *
45
     * @return void
46
     */
47
    public function profidAction($id = null)
48
    {
49
        $user = $this->users->find($id);
50
51
        // Show users gravatar in big size somewhere here.
52
        $this->dispatcher->forward([
0 ignored issues
show
Documentation introduced by
The property dispatcher 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...
53
            'controller' => 'users',
54
            'action'     => 'profile',
55
            'params'    => [$user->acronym ],
56
        ]);
57
    }
58
59
    /**
60
     * Display most active users.
61
     * Sum number of questions and answers contributed.
62
     *
63
     * @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...
64
     *
65
     * @return void
66
     */
67
    public function mostactiveAction($count = 3)
0 ignored issues
show
Unused Code introduced by
The parameter $count 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...
68
    {
69
        $questions = $this->questions->countByUser();
70
        $answers = $this->answers->countByUser();
71
        $comments = $this->comments->countByUser();
72
        $useractivity = array();
0 ignored issues
show
Unused Code introduced by
$useractivity 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...
73
        foreach ($questions as $qActivity) {
74
            $userActivity[$qActivity->user_id] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$userActivity was never initialized. Although not strictly required by PHP, it is generally a good practice to add $userActivity = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
75
                'activity'  => $qActivity->Cnt,
76
                'user_id'   => $qActivity->user_id,
77
            ];
78
        }
79
        foreach ($answers as $Activity) {
80
            $userActivity[$Activity->user_id]['activity'] += $Activity->Cnt;
0 ignored issues
show
Bug introduced by
The variable $userActivity does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
81
        }
82
        foreach ($comments as $Activity) {
83
            $userActivity[$Activity->user_id]['activity'] += $Activity->Cnt;
84
        }
85
        arsort($userActivity);
86
        $mostActiveUsers = array_slice($userActivity, 0, 3, true);
87
        $all = array();
88
        foreach ($mostActiveUsers as $user) {
89
            $all[] = $this->users->find($user['user_id'])->getProperties();
90
        }
91
        $this->views->add('default/page', [
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...
92
            'title'     => 'Mest aktiva användare',
93
            'content'     => '',
94
        ]);
95
        $this->views->add('users/view_short', [
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...
96
            'users' => $all,
97
        ]);
98
    }
99
100
    /**
101
     * Display user with acronym.
102
     *
103
     * @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...
104
     *
105
     * @return void
106
     */
107
    public function profileAction($acronym = null)
108
    {
109
        $user = $this->users->query()
110
        ->where('acronym = ' . "'$acronym'")
111
        ->execute()[0];
112
        // Get user questions
113
        // TODO: move queries to model?
114
        // TODO: use sql count function instead.
115
        $questions = $this->questions->query()
116
        ->where('user_id = ' . "'$user->id'")
117
        ->execute();
118
        $nrOfQuestions = sizeof($questions);
119
        // Build route to user questions and send to view.
120
        $urlQuestions = $this->url->create('questions/list/questions/'.$acronym);
0 ignored issues
show
Documentation introduced by
The property url 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...
121
122
        // Get user answers
123
        $answers = $this->answers->query()
124
        ->where('user_id = ' . "'$user->id'")
125
        ->execute();
126
        $nrOfAnswers = sizeof($answers);
127
        // Build route to user answers and send to view.
128
        $urlAnswers = $this->url->create('questions/list/answers/'.$acronym);
0 ignored issues
show
Documentation introduced by
The property url 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...
129
130
        $gravatarSize = 120;
131
        $user->gravatar = \Anax\Users\User::getGravatar($user->email, $gravatarSize);
132
        $this->theme->setTitle("Byggare $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...
133
        $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...
134
            'user' => $user,
135
            'urlQuestions' => $urlQuestions,
136
            'nrOfQuestions' => $nrOfQuestions,
137
            'urlAnswers' => $urlAnswers,
138
            'nrOfAnswers' => $nrOfAnswers,
139
        ]);
140
141
        // If user is logged in and profile is logged in users show additional links.
142
        if ($this->users->loggedIn()) {
143
            $loggedInUser = $this->users->loggedInUser();
144
            if ($loggedInUser->id == $user->id) {
145
                $this->views->add('default/page', [
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...
146
                    'content' => "Hej {$user->name}. Vad vill du göra? ",
147
                    'links' => [
148
                        [
149
                            'href' => $this->url->create('questions/ask'),
0 ignored issues
show
Documentation introduced by
The property url 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...
150
                            'text' => "Fråga en fråga",
151
                        ],
152
                        [
153
                            'href' => $this->url->create('users/logout'),
0 ignored issues
show
Documentation introduced by
The property url 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...
154
                            'text' => "Logga ut mig",
155
                        ],
156
                        [
157
                            'href' => $this->url->create("users/update/{$user->id}"),
0 ignored issues
show
Documentation introduced by
The property url 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...
158
                            'text' => "Redigera min profil",
159
                        ],
160
                        [
161
                            'href' => $this->url->create('users/add'),
0 ignored issues
show
Documentation introduced by
The property url 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...
162
                            'text' => "Lägg till ny användare",
163
                        ],
164
                    ],
165
                ]);
166
            }
167
        }
168
    }
169
170
    /**
171
     * List all users.
172
     *
173
     * @return void
174
     */
175
    public function listAction()
176
    {
177
        $all = $this->users->findAll();
178
        $gravatarSize = 80;
179
        // TODO: move below to User model?
180
        foreach ($all as $user) {
181
            $user->gravatar = \Anax\Users\User::getGravatar($user->email, $gravatarSize);
182
        }
183
184
        // Display logged in user.
185
        if ($this->users->loggedIn()) {
186
            $user = $this->users->loggedInUser();
187
            // Show users gravatar in big size somewhere here.
188
            $this->dispatcher->forward([
0 ignored issues
show
Documentation introduced by
The property dispatcher 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...
189
                'controller' => 'users',
190
                'action'     => 'profile',
191
                'params'    => [$user->acronym ],
192
                // 'params'    => [$user['acronym'] ],
193
            ]);
194
        } else {
195
            // Dispatch to login Form
196
            $this->dispatcher->forward([
0 ignored issues
show
Documentation introduced by
The property dispatcher 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...
197
                'controller' => 'users',
198
                'action'     => 'login',
199
                'params'    => [ ],
200
            ]);
201
        }
202
203
        $this->theme->setTitle("Byggare");
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...
204
        $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...
205
            'users' => $all,
206
            'title' => "Alla byggare",
207
        ]);
208
    }
209
    /**
210
     * List all users for admin purpose.
211
     *
212
     * @return void
213
     */
214 View Code Duplication
    public function listadminAction()
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...
215
    {
216
        $all = $this->users->findAll();
217
218
        $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...
219
        $this->views->add('users/list-admin', [
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...
220
            'users' => $all,
221
            'title' => "Administrate all users",
222
        ]);
223
    }
224
    /**
225
     * List user with acronym.
226
     *
227
     * @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...
228
     *
229
     * @return void
230
     */
231 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...
232
    {
233
        $user = $this->users->query()
234
        ->where('acronym = ' . "'$acronym'")
235
        ->execute()[0];
236
        $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...
237
        $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...
238
            'user' => $user,
239
        ]);
240
    }
241
    /**
242
     * List user with id for admin purpose.
243
     *
244
     * @param int $id of user to display
245
     *
246
     * @return void
247
     */
248 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...
249
    {
250
        $user = $this->users->find($id);
251
252
        $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...
253
        $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...
254
            'user' => $user,
255
        ]);
256
    }
257
    /**
258
     * Display user as card.
259
     *
260
     * @param int $id of user to display
261
     *
262
     * @return void
263
     */
264
    public function cardAction($id = null, $q_or_a = '', $text = '')
265
    {
266
        $gravatarSize = 40;
267
268
        $user = $this->users->find($id)->getProperties();
269
        $gravatar = \Anax\Users\User::getGravatar($user['email'], $gravatarSize);
270
        $profileUrl = $this->url->create("users/profile/{$user['acronym']}");
0 ignored issues
show
Documentation introduced by
The property url 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...
271
272
        $this->views->add('users/card', [
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...
273
            'user' => $user,
274
            'q_or_a' => $q_or_a,
275
            'gravatar' => $gravatar,
276
            'text' => $text,
277
            'profileUrl' => $profileUrl,
278
        ]);
279
    }
280
281
    /**
282
     * Add new user.
283
     *
284
     * @param string $acronym of user to add.
285
     *
286
     * @return void
287
     */
288 View Code Duplication
    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...
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...
289
    {
290
        if ($this->users->loggedIn()) {
291
            $this->di->session(); // Will load the session service which also starts the session
292
            $form = $this->createAddUserForm();
293
            $form->check([$this, 'callbackSuccess'], [$this, 'callbackFail']);
294
            $this->di->theme->setTitle("Add user");
295
            $this->di->views->add('default/page', [
296
                'title' => "Add user",
297
                'content' => $form->getHTML()
298
            ]);
299
        } else {
300
            $this->redirectTo($this->url->create('users/login'));
0 ignored issues
show
Documentation introduced by
The property url 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...
301
        }
302
    }
303 View Code Duplication
    private function createAddUserForm()
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...
304
    {
305
        return $this->di->form->create([], [
306
            'name' => [
307
                'type'        => 'text',
308
                'label'       => 'Name of person:',
309
                'required'    => true,
310
                'validation'  => ['not_empty'],
311
            ],
312
            'acronym' => [
313
                'type'        => 'text',
314
                'label'       => 'Acronym of person:',
315
                'required'    => true,
316
                'validation'  => ['not_empty'],
317
            ],
318
            'email' => [
319
                'type'        => 'text',
320
                'required'    => true,
321
                'validation'  => ['not_empty', 'email_adress'],
322
            ],
323
            'submit' => [
324
                'type'      => 'submit',
325
                'callback'  => [$this, 'callbackSubmitAddUser'],
326
            ],
327
            // 'submit-fail' => [
328
            //     'type'      => 'submit',
329
            //     'callback'  => [$this, 'callbackSubmitFailAddUser'],
330
            // ],
331
        ]);
332
    }
333
    /**
334
     * Callback for submit-button.
335
     *
336
     */
337
    public function callbackSubmitAddUser($form)
338
    {
339
        // $form->AddOutput("<p>DoSubmit(): Form was submitted.<p>");
340
        // $form->AddOutput("<p>Do stuff (save to database) and return true (success) or false (failed processing)</p>");
341
        $acronym = $form->Value('acronym');
342
        // Check for duplicate acronym. Die if exists.
343
        $all = $this->users->query()
344
            ->where("acronym = '$acronym'")
345
            ->execute();
346
        if (count($all)!=0) {
347
            die("User with acronym $acronym already registered.");
348
        }
349
        // Save user data to database
350
        $now = gmdate('Y-m-d H:i:s');
351
        unset($this->users->session);
352
        $this->users->save([
353
            'acronym' => $form->Value('acronym'),
354
            'email' => $form->Value('email'),
355
            'name' => $form->Value('name'),
356
            'password' => md5($acronym),
357
            'created' => $now,
358
            'active' => $now,
359
        ]);
360
361
        // $form->AddOutput("<p><b>Name: " . $form->Value('name') . "</b></p>");
362
        // $form->AddOutput("<p><b>Email: " . $form->Value('email') . "</b></p>");
363
        // $form->AddOutput("<p><b>Acronym: " . $form->Value('acronym') . "</b></p>");
364
        $form->saveInSession = false;
365
        return true;
366
    }
367
    /**
368
     * Callback for submit-button.
369
     *
370
     */
371
    public function callbackSubmitFailAddUser($form)
372
    {
373
        $form->AddOutput("<p><i>DoSubmitFail(): Form was submitted but I failed to process/save/validate it</i></p>");
374
        return false;
375
    }
376
    /**
377
     * Callback What to do if the form was submitted?
378
     *
379
     */
380
    public function callbackSuccess($form)
381
    {
382
        $form->AddOUtput("<p><i>Form was submitted and the callback method returned true.</i></p>");
383
        $this->redirectTo('users/list/');
384
    }
385
    /**
386
     * Callback What to do when form could not be processed?
387
     *
388
     */
389
    public function callbackFail($form)
390
    {
391
        $form->AddOutput("<p><i>Form was submitted and the Check() method returned false.</i></p>");
392
        $this->redirectTo();
393
    }
394
395
396
    /**
397
     * Update user.
398
     *
399
     * @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...
400
     *
401
     * @return void
402
     */
403
    public function updateAction($id = null)
404
    {
405
        if ($this->users->loggedIn()) {
406
            $this->di->session(); // Will load the session service which also starts the session
407
            // Check if valid entry exists.
408
            $all = $this->users->query()
409
                ->where("id = '$id'")
410
                ->execute();
411
            if (count($all)!=1) {
412
                die("User with id $id not found.");
413
            }
414
            $user = $this->users->find($id);
415
            unset($user->session);
416
            unset($user->gravatar);
417
            $form = $this->createUpdateUserForm($user);
418
            $form->check([$this, 'callbackSuccess'], [$this, 'callbackFail']);
419
            $this->di->theme->setTitle("Updatera profil");
420
            $this->di->views->add('default/page', [
421
                'title' => "Updatera profil",
422
                'content' => $form->getHTML()
423
            ]);
424
        } else {
425
            $this->redirectTo($this->url->create('users/login'));
0 ignored issues
show
Documentation introduced by
The property url 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...
426
        }
427
    }
428
    private function createUpdateUserForm($user = null)
429
    {
430
        return $this->di->form->create([], [
431
            'name' => [
432
                'type'        => 'text',
433
                'value'       => $user->name,
434
                'label'       => 'Name of person:',
435
                'required'    => true,
436
                'validation'  => ['not_empty'],
437
            ],
438
            'acronym' => [
439
                'type'        => 'text',
440
                'value'       => $user->acronym,
441
                'label'       => 'Acronym of person:',
442
                'required'    => true,
443
                'validation'  => ['not_empty'],
444
            ],
445
            'email' => [
446
                'type'        => 'text',
447
                'value'       => $user->email,
448
                'required'    => true,
449
                'validation'  => ['not_empty', 'email_adress'],
450
            ],
451
            'id' => [
452
                'type'        => 'hidden',
453
                'value'       => $user->id,
454
            ],
455
            'submit' => [
456
                'type'      => 'submit',
457
                'label'       => 'Uppdatera',
458
                'callback'  => [$this, 'callbackSubmitUpdateUser'],
459
            ],
460
            'submit-fail' => [
461
                'type'      => 'submit',
462
                'callback'  => [$this, 'callbackSubmitFailUpdateUser'],
463
            ],
464
        ]);
465
    }
466
    public function callbackSubmitUpdateUser($form)
467
    {
468
        // $form->AddOutput("<p>DoSubmit(): Form was submitted.<p>");
469
        // $form->AddOutput("<p>Do stuff (save to database) and return true (success) or false (failed processing)</p>");
470
        // Handle update to duplicate acronym. Die if other user already has acronym.
471
        $id = $form->Value('id');
472
        $acronym = $form->Value('acronym');
473
        $all = $this->users->query()
474
            ->where("id != '$id'")
475
            ->andwhere("acronym = '$acronym'")
476
            ->execute();
477
        if (count($all)==1) {
478
            die("User with acronym $acronym alredy defined for other user. ");
479
        }
480
        // die();
481
        // Save user data to database
482
        $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...
483
        $this->users->save([
484
            'acronym' => $form->Value('acronym'),
485
            'email' => $form->Value('email'),
486
            'name' => $form->Value('name'),
487
            // 'password' => md5($acronym, PASSWORD_DEFAULT),
488
            // 'created' => $now,
489
            // 'active' => $now,
490
        ]);
491
492
        // $form->AddOutput("<p><b>Name: " . $form->Value('name') . "</b></p>");
493
        // $form->AddOutput("<p><b>Email: " . $form->Value('email') . "</b></p>");
494
        // $form->AddOutput("<p><b>Phone: " . $form->Value('acronym') . "</b></p>");
495
        $form->saveInSession = false;
496
        return true;
497
    }
498
    /**
499
     * Callback for submit-button.
500
     *
501
     */
502
    public function callbackSubmitFailUpdateUser($form)
503
    {
504
        $form->AddOutput("<p><i>DoSubmitFail(): Form was submitted but I failed to process/save/validate it</i></p>");
505
        return false;
506
    }
507
508
509
510
    /**
511
     * Delete user.
512
     *
513
     * @param integer $id of user to delete.
514
     *
515
     * @return void
516
     */
517
    public function deleteAction($id = null)
518
    {
519
        if (!isset($id)) {
520
            die("Missing id");
521
        }
522
523
        $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...
524
525
        $this->redirectTo('users/list/');
526
    }
527
    /**
528
     * Delete (soft) user.
529
     *
530
     * @param integer $id of user to delete.
531
     *
532
     * @return void
533
     */
534 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...
535
    {
536
        if (!isset($id)) {
537
            die("Missing id");
538
        }
539
540
        $now = gmdate('Y-m-d H:i:s');
541
542
        $user = $this->users->find($id);
543
544
        $user->deleted = $now;
545
        $user->save();
546
547
        $this->redirectTo('users/list/');
548
    }
549 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...
550
    {
551
        if (!isset($id)) {
552
            die("Missing id");
553
        }
554
555
        $user = $this->users->find($id);
556
557
        $user->deleted = null;
558
        $user->save();
559
560
        $this->redirectTo('users/id/' . $id);
561
    }
562 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...
563
    {
564
        if (!isset($id)) {
565
            die("Missing id");
566
        }
567
568
        $user = $this->users->find($id);
569
570
        $user->active = gmdate('Y-m-d H:i:s');
571
        $user->save();
572
573
        $this->redirectTo('users/id/' . $id);
574
    }
575 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...
576
    {
577
        if (!isset($id)) {
578
            die("Missing id");
579
        }
580
581
        $user = $this->users->find($id);
582
583
        $user->active = null;
584
        $user->save();
585
586
        $this->redirectTo('users/id/' . $id);
587
    }
588
    /**
589
     * List all active and not deleted users.
590
     *
591
     * @return void
592
     */
593 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...
594
    {
595
        $all = $this->users->query()
596
            ->where('active IS NOT NULL')
597
            ->andWhere('deleted is NULL')
598
            ->execute();
599
600
        $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...
601
        $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...
602
            'users' => $all,
603
            'title' => "Users that are active",
604
        ]);
605
    }
606
    /**
607
     * List all inactive and not deleted users.
608
     *
609
     * @return void
610
     */
611 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...
612
    {
613
        $all = $this->users->query()
614
            ->where('active IS NULL')
615
            ->andWhere('deleted is NULL')
616
            ->execute();
617
618
        $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...
619
        $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...
620
            'users' => $all,
621
            'title' => "Users that are inactive",
622
        ]);
623
    }
624
    /**
625
     * List all active and not deleted users.
626
     *
627
     * @return void
628
     */
629 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...
630
    {
631
        $all = $this->users->query()
632
            ->where('deleted is NOT NULL')
633
            ->execute();
634
635
        $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...
636
        $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...
637
            'users' => $all,
638
            'title' => "Users that are in wastebasket",
639
        ]);
640
    }
641
642
    /**
643
     * Logout user.
644
     *
645
     * @return void
646
     */
647
    public function logoutAction()
648
    {
649
        $this->session->set('user_logged_in', null);
0 ignored issues
show
Documentation introduced by
The property session 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...
650
        $this->redirectTo($_SERVER['HTTP_REFERER']);
651
    }
652
    /**
653
     * Login user.
654
     *
655
     * @return void
656
     */
657
    public function loginAction()
658
    {
659
        // TODO: Need to sweep session? How?
660
        // Set saveInSession = false instead.
661
        $this->di->session(); // Will load the session service which also starts the session
662
        $form = $this->createLoginForm();
663
        $form->check([$this, 'callbackLoginSuccess'], [$this, 'callbackLoginSuccess']);
664
        $this->di->theme->setTitle("Logga in");
665
        $this->di->views->add('default/page', [
666
            'title' => "Logga in",
667
            'content' => $form->getHTML()
668
        ]);
669
    }
670 View Code Duplication
    private function createLoginForm()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
671
    {
672
        return $this->di->form->create([], [
673
            'user' => [
674
                'type'        => 'text',
675
                'label'       => 'Användarnamn:',
676
                'required'    => true,
677
                'validation'  => ['not_empty'],
678
            ],
679
            'password' => [
680
                'type'        => 'password',
681
                'label'       => 'Lösenord:',
682
                'required'    => true,
683
                'validation'  => ['not_empty'],
684
            ],
685
            'submit' => [
686
                'type'      => 'submit',
687
                'callback'  => [$this, 'callbackSubmitLogin'],
688
            ],
689
            'submit-fail' => [
690
                'type'      => 'submit',
691
                'callback'  => [$this, 'callbackSubmitFailLogin'],
692
            ],
693
        ]);
694
    }
695
    /**
696
     * Callback for submit-button.
697
     *
698
     */
699
    public function callbackSubmitLogin($form)
700
    {
701
        // $form->AddOutput("<p>DoSubmit(): Form was submitted.<p>");
702
        // $form->AddOutput("<p>Do stuff (save to database) and return true (success) or false (failed processing)</p>");
703
        // Authenticate user.
704
        // Check if user exists
705
        // Check if password matches hash
706
        $userName = $form->Value('user');
707
        $password = $form->Value('password');
708
        $user = $this->users->query()
709
            ->where("acronym = '$userName'")
710
            ->execute();
711
        if (sizeof($user)==1) {
712
            // Set user in session if successful authentication
713
            if (md5($password)==$user[0]->password) {
714
                $this->session->set('user_logged_in', $userName);
0 ignored issues
show
Documentation introduced by
The property session 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...
715
            }
716
        }
717
718
        // $form->AddOutput("<p><b>Användare: " . $form->Value('user') . "</b></p>");
719
        // $form->AddOutput("<p><b>Lösenord: " . $form->Value('password') . "</b></p>");
720
        $form->saveInSession = false;
721
        return true;
722
    }
723
    /**
724
     * Callback for submit-button.
725
     *
726
     */
727
    public function callbackSubmitFailLogin($form)
0 ignored issues
show
Unused Code introduced by
The parameter $form 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...
728
    {
729
        // TODO: Remove this?
730
        // $form->AddOutput("<p><i>DoSubmitFail(): Form was submitted but I failed to process/save/validate it</i></p>");
731
        return false;
732
    }
733
    /**
734
     * Callback What to do if the form was submitted?
735
     *
736
     */
737
    public function callbackLoginSuccess($form)
0 ignored issues
show
Unused Code introduced by
The parameter $form 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...
738
    {
739
        // $form->AddOUtput("<p><i>Form was submitted and the callback method returned true.</i></p>");
740
        // Redirect to page posted from.
741
        $this->redirectTo('users/list');
742
    }
743
    /**
744
     * Callback What to do when form could not be processed?
745
     *
746
     */
747
    public function callbackLoginFail($form)
748
    {
749
        $form->AddOutput("<p><i>Form was submitted and the Check() method returned false.</i></p>");
750
        // Redirect to comment form.
751
        // $this->redirectTo();
752
    }
753
}
754