Completed
Push — master ( 8e4056...923d69 )
by Peder
02:55 queued 01:21
created

src/User/UserActiveRecordModel.php (2 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Peto16\User;
4
5
use \Anax\Database\ActiveRecordModel;
6
use \Peto16\User\UserStorageInterface;
7
8
/**
9
 * Class to handle a user.
10
 */
11
class UserActiveRecordModel extends ActiveRecordModel implements UserStorageInterface
12
{
13
14
    /**
15
    * @var string $tableName name of the database table.
16
    */
17
    protected $tableName = "ramverk1_User";
18
19
    /**
20
     * Columns in the table.
21
     *
22
     * @var integer $id primary key auto incremented.
23
     */
24
25
    public $id;
26
    public $username;
27
    public $password;
28
    public $email;
29
    public $firstname;
30
    public $lastname;
31
    public $administrator;
32
    public $enabled;
33
    public $deleted;
34
35
36
37
    /**
38
     * Create user.
39
     *
40
     * @param  array        $userData Key, value array.
0 ignored issues
show
There is no parameter named $userData. 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...
41
     *
42
     * @return void
43
     */
44 1
    public function createUser(User $user)
45
    {
46 1
        $this->setUserData($user);
47 1
        $this->save();
48 1
    }
49
50
51
52
    /**
53
     * Update user.
54
     *
55
     * @param  array        $user User object.
56
     *
57
     * @return void
58
     */
59 2
    public function updateUser(User $user)
60
    {
61 2
        $this->find("id", $user->id);
62 2
        $this->setUserData($user);
63 2
        $this->save();
64 2
    }
65
66
67
68
    /**
69
     * Delete user.
70
     *
71
     * @param  array        $userData Key, value array.
0 ignored issues
show
There is no parameter named $userData. 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...
72
     *
73
     * @return void
74
     */
75 2
    public function deleteUser($id)
76
    {
77 2
        $user = $this->find("id", $id);
78 2
        $this->id = $user->id;
79 2
        date_default_timezone_set("Europe/Stockholm");
80 2
        $this->deleted = date("Y-m-d H:i:s");
81 2
        $this->save();
82 2
    }
83
84
85
86
    /**
87
     * Dynamicly set user properties to its value.
88
     *
89
     * @param array            $user user object
90
     */
91 3
    public function setUserData(User $user)
92
    {
93 3
        $userVarArray = get_object_vars($user);
94
95 3
        foreach ($userVarArray as $key => $value) {
96 3
            if ($value != null) {
97 3
                $this->{$key} = $value;
98 3
            }
99 3
        }
100 3
    }
101
102
103
104
    /**
105
     * Dynamicly get user by field.
106
     *
107
     * @param  string          $field Fieldname to search.
108
     *
109
     * @param  mixed           $data Data to search for in the field.
110
     *
111
     * @return User            Returns a user.
112
     */
113 10
    public function getUserByField($field, $data)
114
    {
115 10
        return $this->find($field, $data);
116
    }
117
118
119
120
    /**
121
     * Returns all users stored and that are not deleted.
122
     *
123
     * @return array           Array with all users.
124
     */
125 2
    public function findAllUsers()
126
    {
127 2
        $this->checkDb();
128 2
        return $this->db->connect()
129 2
                        ->select()
130 2
                        ->from($this->tableName)
131 2
                        ->where("deleted IS NULL")
132 2
                        ->execute()
133 2
                        ->fetchAllClass(get_class($this));
134
    }
135
}
136