Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
11 | class User extends ActiveModel implements iUser |
||
12 | { |
||
13 | |||
14 | /** |
||
15 | * Get user object relation. If $user_id is null - get current session user |
||
16 | * @param int|null $user_id |
||
17 | * @return self|null |
||
18 | */ |
||
19 | public static function identity($user_id = null) |
||
47 | |||
48 | /** |
||
49 | * Get current user id if auth |
||
50 | * @return int |
||
51 | */ |
||
52 | public function getId() |
||
56 | |||
57 | /** |
||
58 | * Get user param |
||
59 | * @param string $param |
||
60 | * @param null|string $defaultValue |
||
61 | * @return string|int|null |
||
62 | */ |
||
63 | public function getParam($param, $defaultValue = null) |
||
67 | |||
68 | /** |
||
69 | * Check if current user session is auth |
||
70 | * @return bool |
||
71 | */ |
||
72 | public static function isAuth() |
||
97 | |||
98 | /** |
||
99 | * Check if user with $id exist |
||
100 | * @param int $id |
||
101 | * @return bool |
||
102 | */ |
||
103 | public static function isExist($id) |
||
120 | |||
121 | /** |
||
122 | * Check if use with $email is exist |
||
123 | * @param string $email |
||
124 | * @return bool |
||
125 | */ |
||
126 | View Code Duplication | public static function isMailExist($email) |
|
134 | |||
135 | /** |
||
136 | * Check if user with $login is exist |
||
137 | * @param string $login |
||
138 | * @return bool |
||
139 | */ |
||
140 | View Code Duplication | public static function isLoginExist($login) |
|
148 | |||
149 | /** |
||
150 | * Get user person like a object via email |
||
151 | * @param string $email |
||
152 | * @return null|static |
||
153 | */ |
||
154 | public static function getIdentityViaEmail($email) |
||
162 | |||
163 | /** |
||
164 | * Get relation one-to-many for user wall posts. Ex: User::find(1)->getWall()->offset() |
||
165 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
166 | */ |
||
167 | public function getWall() |
||
171 | |||
172 | /** |
||
173 | * Get user role object |
||
174 | * @return \Apps\ActiveRecord\Role|null |
||
175 | */ |
||
176 | public function getRole() |
||
180 | |||
181 | /** |
||
182 | * Get user profile data as relation of user table. Ex: User::find(1)->getProfile()->nick |
||
183 | * @return \Apps\ActiveRecord\Profile |
||
184 | */ |
||
185 | public function getProfile() |
||
186 | { |
||
187 | // lets find profile identity via current user id |
||
188 | $object = Profile::identity($this->getId()); |
||
189 | // is not exist? Hmmm, lets create it! |
||
190 | if ($object === null && $this->getId() > 0) { |
||
191 | $object = new Profile(); |
||
192 | $object->user_id = $this->getId(); |
||
193 | $object->save(); |
||
194 | } |
||
195 | // return result ;) |
||
196 | return $object; |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * Check if target user in blacklist |
||
201 | * @param int $target_id |
||
202 | * @return bool |
||
203 | */ |
||
204 | public function inBlacklist($target_id) |
||
208 | |||
209 | } |
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.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.