Passed
Push — master ( 700b0f...aafb0a )
by Björn
18:25 queued 10s
created

User::getUserId()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * BB's Zend Framework 2 Components
4
 *
5
 * AdminModule
6
 *
7
 * @package   [MyApplication]
8
 * @package   BB's Zend Framework 2 Components
9
 * @package   AdminModule
10
 * @author    Björn Bartels <[email protected]>
11
 * @link      https://gitlab.bjoernbartels.earth/groups/zf2
12
 * @license   http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
13
 * @copyright copyright (c) 2016 Björn Bartels <[email protected]>
14
 */
15
16
namespace Admin\Entity;
17
18
use \ZfcUser\Entity\User as ZfcUser;
19
use Zend\Crypt\Password\Bcrypt;
20
21
class User extends ZfcUser
22
{
23
    
24
    /**
25
     * user's confirmation/activation token
26
  *
27
     * @var string
28
     */
29
    protected $token;
30
31
    /**
32
     * user's ACL role
33
  *
34
     * @var string
35
     */
36
    protected $aclrole;
37
38
    /**
39
     * user's ID
40
  *
41
     * @var int
42
     */
43
    protected $user_id;
44
    
45
    /**
46
     * Get ACL role.
47
     *
48
     * @return STRING
49
     */
50
    public function getAclrole()
51
    {
52
        if (empty($this->aclrole)) {
53
            $this->setAclrole('public');
54
        }
55
        return $this->aclrole;
56
    }
57
58
    /**
59
     * Set ACL role.
60
     *
61
     * @param  STRING $aclrole
62
     * @return \Admin\Entity\User
63
     */
64
    public function setAclrole($aclrole)
65
    {
66
        $this->aclrole = $aclrole;
67
        return $this;
68
    }
69
    
70
    /**
71
     * Get token string.
72
     *
73
     * @return STRING
74
     */
75
    public function getToken()
76
    {
77
        return $this->token;
78
    }
79
80
    /**
81
     * Set token string.
82
     *
83
     * @param  STRING $aclrole
0 ignored issues
show
Bug introduced by
There is no parameter named $aclrole. 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...
84
     * @return \Admin\Entity\User
85
     */
86
    public function setToken($token)
87
    {
88
        $this->token = $token;
89
        return $this;
90
    }
91
92
    /**
93
     * Get user-id string.
94
     *
95
     * @return STRING
96
     */
97
    public function getUserId()
98
    {
99
        if (null === $this->user_id) {
100
            $this->setUserId($this->getId());
101
        }
102
        return $this->user_id;
103
    }
104
105
    /**
106
     * Set user-id string.
107
     *
108
     * @param  STRING $aclrole
0 ignored issues
show
Bug introduced by
There is no parameter named $aclrole. 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...
109
     * @return \Admin\Entity\User
110
     */
111
    public function setUserId($user_id)
112
    {
113
        $this->user_id = $user_id;
114
        return $this;
115
    }
116
117
118
    
119
    /**
120
     * set user's object property data
121
  *
122
     * @param  array   $data
123
     * @param  boolean $forceEncryptPassword
124
     * @return \Admin\Entity\User
125
     */
126 View Code Duplication
    public function exchangeArray($data = array(), $forceEncryptPassword = false)
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...
127
    {
128
        if (isset($data['id']) && !empty($data["id"]) ) {
129
            $this->id            = ($data['id']);
130
            $this->user_id        = ($data['id']);
131
        } elseif (isset($data['user_id']) && !empty($data["user_id"]) ) {
132
            $this->id            = ($data['user_id']);
133
            $this->user_id        = ($data['user_id']);
134
        }
135
        $this->username        = (isset($data['username'])) ? $data['username'] : $this->username;
136
        $this->email        = (isset($data['email'])) ? $data['email'] : $this->email;
137
        if (isset($data['displayName']) ) {
138
            $this->display_name    = $data['displayName'];
0 ignored issues
show
Bug introduced by
The property display_name 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...
139
            $this->displayName    = $data['displayName'];
140
        } elseif (isset($data['display_name']) ) {
141
            $this->display_name    = $data['display_name'];
142
            $this->displayName    = $data['display_name'];
143
        }
144
        if (isset($data["password"]) && $forceEncryptPassword ) {
145
            $bcrypt = new Bcrypt;
146
            $bcrypt->setCost(null); // @TODO $this->getUserService()->getOptions()->getPasswordCost());
147
            $data["password"] = $bcrypt->create($data['password']);
148
        }
149
        $this->password        = (isset($data['password'])) ? $data['password'] : $this->password;
150
        $this->state        = (isset($data['state'])) ? $data['state'] : $this->state;
151
        $this->aclrole        = (isset($data['aclrole'])) ? $data['aclrole'] : $this->aclrole;
152
        $this->token        = (isset($data['token'])) ? $data['token'] : $this->token;
153
        
154
        return $this;
155
    }
156
    
157
    /**
158
     * get copy of user's object properties in an assosiative array
159
  *
160
     * @return array
161
     */
162
    public function __getArrayCopy()
163
    {
164
        return array(
165
        "id"            => $this->getId(),
166
        "user_id"        => $this->getUserId(),
167
        "username"        => $this->getUsername(),
168
        "email"            => $this->getEmail(),
169
        "display_name"    => $this->getDisplayName(),
170
        "displayName"    => $this->getDisplayName(),
171
        "password"        => $this->getPassword(),
172
        "state"            => $this->getState(),
173
        "aclrole"        => $this->getAclrole(),
174
        "token"            => $this->getToken(),
175
        );
176
    }
177
    
178
    /**
179
     * get copy of user's object properties in an assosiative array
180
  *
181
     * @return array
182
     * /
183
    public function getArrayCopy() 
184
    {
185
        return $this->__getArrayCopy();
186
    } // collides with some magic "__get" method in ZfcUser parent ?! 
187
*/
188
    
189
}
190