Conditions | 12 |
Paths | 22 |
Total Lines | 76 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
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 |
||
92 | public function authenticateRequest(HTTPRequest $request) |
||
93 | { |
||
94 | $uidAndToken = Cookie::get($this->getTokenCookieName()); |
||
95 | $deviceID = Cookie::get($this->getDeviceCookieName()); |
||
96 | |||
97 | // @todo Consider better placement of database_is_ready test |
||
98 | if (!$deviceID || strpos($uidAndToken, ':') === false || !Security::database_is_ready()) { |
||
99 | return; |
||
100 | } |
||
101 | |||
102 | list($uid, $token) = explode(':', $uidAndToken, 2); |
||
103 | |||
104 | if (!$uid || !$token) { |
||
105 | return; |
||
106 | } |
||
107 | |||
108 | /** @var Member $member */ |
||
109 | $member = Member::get()->byID($uid); |
||
110 | |||
111 | /** @var RememberLoginHash $rememberLoginHash */ |
||
112 | $rememberLoginHash = null; |
||
113 | |||
114 | // check if autologin token matches |
||
115 | if ($member) { |
||
116 | $hash = $member->encryptWithUserSettings($token); |
||
117 | $rememberLoginHash = RememberLoginHash::get() |
||
118 | ->filter(array( |
||
119 | 'MemberID' => $member->ID, |
||
120 | 'DeviceID' => $deviceID, |
||
121 | 'Hash' => $hash |
||
122 | ))->first(); |
||
123 | |||
124 | if (!$rememberLoginHash) { |
||
125 | $member = null; |
||
126 | } else { |
||
127 | // Check for expired token |
||
128 | $expiryDate = new \DateTime($rememberLoginHash->ExpiryDate); |
||
129 | $now = DBDatetime::now(); |
||
130 | $now = new \DateTime($now->Rfc2822()); |
||
131 | if ($now > $expiryDate) { |
||
132 | $member = null; |
||
133 | } |
||
134 | } |
||
135 | } |
||
136 | |||
137 | if ($member) { |
||
138 | if ($this->cascadeLogInTo) { |
||
139 | // @todo look at how to block "regular login" triggers from happening here |
||
140 | // @todo deal with the fact that the Session::current_session() isn't correct here :-/ |
||
141 | $this->cascadeLogInTo->logIn($member, false, $request); |
||
142 | //\SilverStripe\Dev\Debug::message('here'); |
||
143 | } |
||
144 | |||
145 | // @todo Consider whether response should be part of logIn() as well |
||
146 | |||
147 | // Renew the token |
||
148 | if ($rememberLoginHash) { |
||
149 | $rememberLoginHash->renew(); |
||
150 | $tokenExpiryDays = RememberLoginHash::config()->uninherited('token_expiry_days'); |
||
151 | Cookie::set( |
||
152 | $this->getTokenCookieName(), |
||
153 | $member->ID . ':' . $rememberLoginHash->getToken(), |
||
154 | $tokenExpiryDays, |
||
155 | null, |
||
156 | null, |
||
157 | false, |
||
158 | true |
||
159 | ); |
||
160 | } |
||
161 | |||
162 | return $member; |
||
163 | |||
164 | // Audit logging hook |
||
165 | $member->extend('memberAutoLoggedIn'); |
||
166 | } |
||
167 | } |
||
168 | |||
224 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.