1 | <?php |
||
28 | class User extends ActiveRecord implements IdentityInterface |
||
29 | { |
||
30 | const STATUS_INACTIVE = 0; |
||
31 | const STATUS_ACTIVE = 10; |
||
32 | |||
33 | /** |
||
34 | * @inheritdoc |
||
35 | */ |
||
36 | public static function tableName() |
||
40 | |||
41 | /** |
||
42 | * @inheritdoc |
||
43 | */ |
||
44 | public function behaviors() |
||
50 | |||
51 | /** |
||
52 | * @inheritdoc |
||
53 | */ |
||
54 | public function rules() |
||
61 | |||
62 | /** |
||
63 | * @inheritdoc |
||
64 | */ |
||
65 | public static function findIdentity($id) |
||
69 | |||
70 | /** |
||
71 | * @inheritdoc |
||
72 | */ |
||
73 | public static function findIdentityByAccessToken($token, $type = null) |
||
77 | |||
78 | /** |
||
79 | * Finds user by username |
||
80 | * |
||
81 | * @param string $username |
||
82 | * @return static|null |
||
83 | */ |
||
84 | public static function findByUsername($username) |
||
88 | |||
89 | /** |
||
90 | * Finds user by password reset token |
||
91 | * |
||
92 | * @param string $token password reset token |
||
93 | * @return static|null |
||
94 | */ |
||
95 | public static function findByPasswordResetToken($token) |
||
106 | |||
107 | /** |
||
108 | * Finds out if password reset token is valid |
||
109 | * |
||
110 | * @param string $token password reset token |
||
111 | * @return boolean |
||
112 | */ |
||
113 | public static function isPasswordResetTokenValid($token) |
||
123 | |||
124 | /** |
||
125 | * @inheritdoc |
||
126 | */ |
||
127 | public function getId() |
||
131 | |||
132 | /** |
||
133 | * @inheritdoc |
||
134 | */ |
||
135 | public function getAuthKey() |
||
139 | |||
140 | /** |
||
141 | * @inheritdoc |
||
142 | */ |
||
143 | public function validateAuthKey($authKey) |
||
147 | |||
148 | /** |
||
149 | * Validates password |
||
150 | * |
||
151 | * @param string $password password to validate |
||
152 | * @return boolean if password provided is valid for current user |
||
153 | */ |
||
154 | public function validatePassword($password) |
||
158 | |||
159 | /** |
||
160 | * Generates password hash from password and sets it to the model |
||
161 | * |
||
162 | * @param string $password |
||
163 | */ |
||
164 | public function setPassword($password) |
||
168 | |||
169 | /** |
||
170 | * Generates "remember me" authentication key |
||
171 | */ |
||
172 | public function generateAuthKey() |
||
176 | |||
177 | /** |
||
178 | * Generates new password reset token |
||
179 | */ |
||
180 | public function generatePasswordResetToken() |
||
184 | |||
185 | /** |
||
186 | * Removes password reset token |
||
187 | */ |
||
188 | public function removePasswordResetToken() |
||
192 | |||
193 | public static function getDb() |
||
197 | } |
||
198 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.