| Conditions | 9 |
| Paths | 256 |
| Total Lines | 87 |
| Code Lines | 59 |
| Lines | 0 |
| Ratio | 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 |
||
| 142 | protected function runUserTests(auth_plugin_authpdo $auth, $user) { |
||
| 143 | global $conf; |
||
| 144 | $info = 'DSN: ' . $auth->getConf('dsn') . ' User:' . $user['user']; |
||
| 145 | |||
| 146 | // minimal setup |
||
| 147 | $this->assertTrue($auth->checkPass($user['user'], $user['pass']), $info); |
||
| 148 | $check = $auth->getUserData($user['user']); |
||
| 149 | $this->assertEquals($user['user'], $check['user'], $info); |
||
| 150 | $this->assertEquals($user['name'], $check['name'], $info); |
||
| 151 | $this->assertEquals($user['mail'], $check['mail'], $info); |
||
| 152 | $groups = array_merge($user['grps'], array($conf['defaultgroup'])); |
||
| 153 | $this->assertEquals($groups, $check['grps'], $info); |
||
| 154 | |||
| 155 | // getUsers |
||
| 156 | if($auth->canDo('getUsers')) { |
||
| 157 | $list = $auth->retrieveUsers(0, -1, array('user' => $user['user'])); |
||
| 158 | $this->assertGreaterThanOrEqual(1, count($list)); |
||
| 159 | $list = $auth->retrieveUsers(0, -1, array('name' => $user['name'])); |
||
| 160 | $this->assertGreaterThanOrEqual(1, count($list)); |
||
| 161 | $list = $auth->retrieveUsers(0, -1, array('mail' => $user['mail'])); |
||
| 162 | $this->assertGreaterThanOrEqual(1, count($list)); |
||
| 163 | } |
||
| 164 | |||
| 165 | // getUserCount |
||
| 166 | if($auth->canDo('getUserCount')) { |
||
| 167 | $count = $auth->getUserCount(array('user' => $user['user'])); |
||
| 168 | $this->assertGreaterThanOrEqual(1, $count); |
||
| 169 | $count = $auth->getUserCount(array('name' => $user['name'])); |
||
| 170 | $this->assertGreaterThanOrEqual(1, $count); |
||
| 171 | $count = $auth->getUserCount(array('mail' => $user['mail'])); |
||
| 172 | $this->assertGreaterThanOrEqual(1, $count); |
||
| 173 | } |
||
| 174 | |||
| 175 | // modGroups |
||
| 176 | if($auth->canDo('modGroups')) { |
||
| 177 | $newgroup = 'foobar'; |
||
| 178 | $ok = $auth->modifyUser($user['user'], array('grps' => array($newgroup))); |
||
| 179 | $this->assertTrue($ok, $info); |
||
| 180 | $check = $auth->getUserData($user['user']); |
||
| 181 | $this->assertTrue(in_array($newgroup, $check['grps']), $info); |
||
| 182 | } |
||
| 183 | |||
| 184 | // modPass |
||
| 185 | if($auth->canDo('modPass')) { |
||
| 186 | $newpass = 'foobar'; |
||
| 187 | $ok = $auth->modifyUser($user['user'], array('pass' => $newpass)); |
||
| 188 | $this->assertTrue($ok, $info); |
||
| 189 | $this->assertTrue($auth->checkPass($user['user'], $newpass), $info); |
||
| 190 | } |
||
| 191 | |||
| 192 | // modMail |
||
| 193 | if($auth->canDo('modMail')) { |
||
| 194 | $newmail = '[email protected]'; |
||
| 195 | $ok = $auth->modifyUser($user['user'], array('mail' => $newmail)); |
||
| 196 | $this->assertTrue($ok, $info); |
||
| 197 | $check = $auth->getUserData($user['user']); |
||
| 198 | $this->assertEquals($newmail, $check['mail'], $info); |
||
| 199 | } |
||
| 200 | |||
| 201 | // modName |
||
| 202 | if($auth->canDo('modName')) { |
||
| 203 | $newname = 'FirstName Foobar'; |
||
| 204 | $ok = $auth->modifyUser($user['user'], array('name' => $newname)); |
||
| 205 | $this->assertTrue($ok, $info); |
||
| 206 | $check = $auth->getUserData($user['user']); |
||
| 207 | $this->assertEquals($newname, $check['name'], $info); |
||
| 208 | } |
||
| 209 | |||
| 210 | // modLogin |
||
| 211 | if($auth->canDo('modLogin')) { |
||
| 212 | $newuser = 'foobar' . $user['user']; |
||
| 213 | $ok = $auth->modifyUser($user['user'], array('user' => $newuser)); |
||
| 214 | $this->assertTrue($ok, $info); |
||
| 215 | $check = $auth->getUserData($newuser); |
||
| 216 | $this->assertEquals($newuser, $check['user'], $info); |
||
| 217 | // rename back |
||
| 218 | $ok = $auth->modifyUser($newuser, array('user' => $user['user'])); |
||
| 219 | $this->assertTrue($ok, $info); |
||
| 220 | } |
||
| 221 | |||
| 222 | // delUser |
||
| 223 | if($auth->canDo('delUser')) { |
||
| 224 | $num = $auth->deleteUsers(array($user['user'])); |
||
| 225 | $this->assertEquals(1, $num, $info); |
||
| 226 | $this->assertFalse($auth->getUserData($user['user']), $info); |
||
| 227 | } |
||
| 228 | } |
||
| 229 | |||
| 269 |
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.