Conditions | 13 |
Paths | 296 |
Total Lines | 153 |
Code Lines | 54 |
Lines | 10 |
Ratio | 6.54 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
88 | public function createUserSession($user_id = '', $email = '', $nick = '') |
||
89 | { |
||
90 | // Initialize the User Object |
||
91 | $this->user = null; |
||
92 | |||
93 | /* |
||
94 | * Get User via DB Queries |
||
95 | * |
||
96 | * 1) user_id |
||
97 | * 2) email |
||
98 | * 3) nick |
||
99 | */ |
||
100 | if (empty($user_id) === false) { |
||
101 | // Get the user from the user_id |
||
102 | $this->user = Doctrine_Query::create() |
||
103 | #->select('u.*,g.*,o.*') |
||
104 | ->from('CsUsers u') |
||
105 | ->leftJoin('u.CsOptions o') |
||
106 | #->leftJoin('u.CsGroups g') |
||
107 | ->where('u.user_id = ?') |
||
108 | ->fetchOne([$user_id], Doctrine::HYDRATE_ARRAY); |
||
109 | } elseif (empty($email) === false) { |
||
110 | // Get the user from the email |
||
111 | $this->user = Doctrine_Query::create() |
||
112 | #->select('u.*,g.*,o.*') |
||
113 | ->from('CsUsers u') |
||
114 | ->leftJoin('u.CsOptions o') |
||
115 | #->leftJoin('u.CsGroups g') |
||
116 | ->where('u.email = ?') |
||
117 | ->fetchOne([$email], Doctrine::HYDRATE_ARRAY); |
||
118 | } elseif (empty($nick) === false) { |
||
119 | // Get the user from the nick |
||
120 | $this->user = Doctrine_Query::create() |
||
121 | #->select('u.*,g.*,o.*') |
||
122 | ->from('CsUsers u') |
||
123 | ->leftJoin('u.CsOptions o') |
||
124 | #->leftJoin('u.CsGroups g') |
||
125 | ->where('u.nick = ?') |
||
126 | ->fetchOne([$nick], Doctrine::HYDRATE_ARRAY); |
||
127 | } |
||
128 | |||
129 | /* |
||
130 | * Check if this user is activated, |
||
131 | * else reset cookie, session and redirect |
||
132 | */ |
||
133 | if (is_array($this->user) and $this->user['activated'] === 0) { |
||
134 | $this->logoutUser(); |
||
135 | |||
136 | // redirect |
||
137 | $message = _('Your account is not yet activated.'); |
||
138 | |||
139 | \Koch\Http\HttpResponse::redirect('/account/activation_email', 5, 403, $message); |
||
140 | } |
||
141 | |||
142 | /* |
||
143 | * Create $_SESSION['user'] array, containing user data |
||
144 | */ |
||
145 | if (is_array($this->user)) { |
||
146 | /* |
||
147 | * Transfer User Data into Session |
||
148 | */ |
||
149 | #\Koch\Debug\Debug::firebug($_SESSION); |
||
150 | #\Koch\Debug\Debug::firebug($this->config); |
||
151 | |||
152 | $_SESSION['user']['authed'] = 1; |
||
153 | $_SESSION['user']['user_id'] = $this->user['user_id']; |
||
154 | |||
155 | $_SESSION['user']['passwordhash'] = $this->user['passwordhash']; |
||
156 | $_SESSION['user']['email'] = $this->user['email']; |
||
157 | $_SESSION['user']['nick'] = $this->user['nick']; |
||
158 | |||
159 | $_SESSION['user']['disabled'] = $this->user['disabled']; |
||
160 | $_SESSION['user']['activated'] = $this->user['activated']; |
||
161 | |||
162 | /* |
||
163 | * SetLanguage |
||
164 | * |
||
165 | * At this position the language might already by set by |
||
166 | * the language_via_get filter. the language value set via GET |
||
167 | * precedes over the user config and the general config |
||
168 | * the full order is |
||
169 | * a) language_via_get filter |
||
170 | * a) user['language'] from database / personal user setting |
||
171 | * b) standard language / fallback as defined by $this->config['locale']['locale'] |
||
172 | */ |
||
173 | if (false === isset($_SESSION['user']['language_via_url'])) { |
||
174 | $_SESSION['user']['language'] = (false === empty($this->user['language'])) |
||
175 | ? $this->user['language'] |
||
176 | : $this->config['locale']['default']; |
||
177 | } |
||
178 | |||
179 | /** |
||
180 | * Frontend-Theme. |
||
181 | * |
||
182 | * first take standard theme as defined by $config->theme |
||
183 | * |
||
184 | * @todo remove $_REQUEST, frontend theme is selectable via frontend |
||
185 | */ |
||
186 | View Code Duplication | if (false === isset($_REQUEST['theme'])) { |
|
187 | $_SESSION['user']['frontend_theme'] = (!empty($this->user['frontend_theme'])) |
||
188 | ? $this->user['frontend_theme'] |
||
189 | : $this->config['template']['frontend_theme']; |
||
190 | } |
||
191 | |||
192 | /* |
||
193 | * Backend-Theme |
||
194 | */ |
||
195 | View Code Duplication | if (empty($this->user['backend_theme']) === false) { |
|
196 | $_SESSION['user']['backend_theme'] = $this->user['backend_theme']; |
||
197 | } else { |
||
198 | $_SESSION['user']['backend_theme'] = $this->config['template']['backend_theme']; |
||
199 | } |
||
200 | |||
201 | /* |
||
202 | * Permissions |
||
203 | * |
||
204 | * Get Group & Rights of user_id |
||
205 | */ |
||
206 | /* |
||
207 | User-Datensatz beinhaltet ein CsGroups-Array |
||
208 | user => Array ( |
||
209 | [user_id] => 1 |
||
210 | ... |
||
211 | [CsGroups] => Array ( |
||
212 | [0] => Array ( |
||
213 | [group_id] => 3 |
||
214 | ... |
||
215 | [role_id] => 5 |
||
216 | ) |
||
217 | ) |
||
218 | ) |
||
219 | */ |
||
220 | // Initialize User Session Arrays |
||
221 | $_SESSION['user']['group'] = ''; |
||
222 | $_SESSION['user']['rights'] = ''; |
||
223 | |||
224 | if (false === empty($this->user['CsGroups'])) { |
||
225 | $_SESSION['user']['group'] = $this->user['CsGroups'][0]['group_id']; |
||
226 | $_SESSION['user']['role'] = $this->user['CsGroups'][0]['role_id']; |
||
227 | $_SESSION['user']['rights'] = Koch\ACL::createRightSession( |
||
228 | $_SESSION['user']['role'], |
||
229 | $this->user['user_id'] |
||
230 | ); |
||
231 | } |
||
232 | |||
233 | #\Koch\Debug\Debug::firebug($_SESSION); |
||
234 | } else { |
||
235 | // this resets the $_SESSION['user'] array |
||
236 | GuestUser::instantiate(); |
||
237 | |||
238 | #Koch\Debug\Debug::printR($_SESSION); |
||
239 | } |
||
240 | } |
||
241 | |||
489 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.