| Conditions | 9 |
| Paths | 256 |
| Total Lines | 87 |
| Code Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 165 | protected function runUserTests(auth_plugin_authpdo $auth, $user) { |
||
| 166 | global $conf; |
||
| 167 | $info = 'DSN: ' . $auth->getConf('dsn') . ' User:' . $user['user']; |
||
| 168 | |||
| 169 | // minimal setup |
||
| 170 | $this->assertTrue($auth->checkPass($user['user'], $user['pass']), $info); |
||
| 171 | $check = $auth->getUserData($user['user']); |
||
| 172 | $this->assertEquals($user['user'], $check['user'], $info); |
||
| 173 | $this->assertEquals($user['name'], $check['name'], $info); |
||
| 174 | $this->assertEquals($user['mail'], $check['mail'], $info); |
||
| 175 | $groups = array_merge($user['grps'], array($conf['defaultgroup'])); |
||
| 176 | $this->assertEquals($groups, $check['grps'], $info); |
||
| 177 | |||
| 178 | // getUsers |
||
| 179 | if($auth->canDo('getUsers')) { |
||
| 180 | $list = $auth->retrieveUsers(0, -1, array('user' => $user['user'])); |
||
| 181 | $this->assertGreaterThanOrEqual(1, count($list)); |
||
| 182 | $list = $auth->retrieveUsers(0, -1, array('name' => $user['name'])); |
||
| 183 | $this->assertGreaterThanOrEqual(1, count($list)); |
||
| 184 | $list = $auth->retrieveUsers(0, -1, array('mail' => $user['mail'])); |
||
| 185 | $this->assertGreaterThanOrEqual(1, count($list)); |
||
| 186 | } |
||
| 187 | |||
| 188 | // getUserCount |
||
| 189 | if($auth->canDo('getUserCount')) { |
||
| 190 | $count = $auth->getUserCount(array('user' => $user['user'])); |
||
| 191 | $this->assertGreaterThanOrEqual(1, $count); |
||
| 192 | $count = $auth->getUserCount(array('name' => $user['name'])); |
||
| 193 | $this->assertGreaterThanOrEqual(1, $count); |
||
| 194 | $count = $auth->getUserCount(array('mail' => $user['mail'])); |
||
| 195 | $this->assertGreaterThanOrEqual(1, $count); |
||
| 196 | } |
||
| 197 | |||
| 198 | // modGroups |
||
| 199 | if($auth->canDo('modGroups')) { |
||
| 200 | $newgroup = 'foobar'; |
||
| 201 | $ok = $auth->modifyUser($user['user'], array('grps' => array($newgroup))); |
||
| 202 | $this->assertTrue($ok, $info); |
||
| 203 | $check = $auth->getUserData($user['user']); |
||
| 204 | $this->assertTrue(in_array($newgroup, $check['grps']), $info); |
||
| 205 | } |
||
| 206 | |||
| 207 | // modPass |
||
| 208 | if($auth->canDo('modPass')) { |
||
| 209 | $newpass = 'foobar'; |
||
| 210 | $ok = $auth->modifyUser($user['user'], array('pass' => $newpass)); |
||
| 211 | $this->assertTrue($ok, $info); |
||
| 212 | $this->assertTrue($auth->checkPass($user['user'], $newpass), $info); |
||
| 213 | } |
||
| 214 | |||
| 215 | // modMail |
||
| 216 | if($auth->canDo('modMail')) { |
||
| 217 | $newmail = '[email protected]'; |
||
| 218 | $ok = $auth->modifyUser($user['user'], array('mail' => $newmail)); |
||
| 219 | $this->assertTrue($ok, $info); |
||
| 220 | $check = $auth->getUserData($user['user']); |
||
| 221 | $this->assertEquals($newmail, $check['mail'], $info); |
||
| 222 | } |
||
| 223 | |||
| 224 | // modName |
||
| 225 | if($auth->canDo('modName')) { |
||
| 226 | $newname = 'FirstName Foobar'; |
||
| 227 | $ok = $auth->modifyUser($user['user'], array('name' => $newname)); |
||
| 228 | $this->assertTrue($ok, $info); |
||
| 229 | $check = $auth->getUserData($user['user']); |
||
| 230 | $this->assertEquals($newname, $check['name'], $info); |
||
| 231 | } |
||
| 232 | |||
| 233 | // modLogin |
||
| 234 | if($auth->canDo('modLogin')) { |
||
| 235 | $newuser = 'foobar' . $user['user']; |
||
| 236 | $ok = $auth->modifyUser($user['user'], array('user' => $newuser)); |
||
| 237 | $this->assertTrue($ok, $info); |
||
| 238 | $check = $auth->getUserData($newuser); |
||
| 239 | $this->assertEquals($newuser, $check['user'], $info); |
||
| 240 | // rename back |
||
| 241 | $ok = $auth->modifyUser($newuser, array('user' => $user['user'])); |
||
| 242 | $this->assertTrue($ok, $info); |
||
| 243 | } |
||
| 244 | |||
| 245 | // delUser |
||
| 246 | if($auth->canDo('delUser')) { |
||
| 247 | $num = $auth->deleteUsers(array($user['user'])); |
||
| 248 | $this->assertEquals(1, $num, $info); |
||
| 249 | $this->assertFalse($auth->getUserData($user['user']), $info); |
||
| 250 | } |
||
| 251 | } |
||
| 252 | |||
| 316 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.