| Conditions | 7 |
| Paths | 64 |
| Total Lines | 69 |
| Code Lines | 47 |
| 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 |
||
| 112 | protected function runUserTests(auth_plugin_authpdo $auth, $user) { |
||
| 113 | global $conf; |
||
| 114 | $info = 'testing ' . $user['user']; |
||
| 115 | |||
| 116 | // minimal setup |
||
| 117 | $this->assertTrue($auth->checkPass($user['user'], $user['pass']), $info); |
||
| 118 | $check = $auth->getUserData($user['user']); |
||
| 119 | $this->assertEquals($user['user'], $check['user'], $info); |
||
| 120 | $this->assertEquals($user['name'], $check['name'], $info); |
||
| 121 | $this->assertEquals($user['mail'], $check['mail'], $info); |
||
| 122 | $groups = array_merge($user['grps'], array($conf['defaultgroup'])); |
||
| 123 | $this->assertEquals($groups, $check['grps'], $info); |
||
| 124 | |||
| 125 | // getUsers |
||
| 126 | if($auth->canDo('getUsers')) { |
||
| 127 | $list = $auth->retrieveUsers(0, -1, array('user' => $user['user'])); |
||
| 128 | $this->assertGreaterThanOrEqual(1, count($list)); |
||
| 129 | $list = $auth->retrieveUsers(0, -1, array('name' => $user['name'])); |
||
| 130 | $this->assertGreaterThanOrEqual(1, count($list)); |
||
| 131 | $list = $auth->retrieveUsers(0, -1, array('mail' => $user['mail'])); |
||
| 132 | $this->assertGreaterThanOrEqual(1, count($list)); |
||
| 133 | } |
||
| 134 | |||
| 135 | // getUserCount |
||
| 136 | if($auth->canDo('getUserCount')) { |
||
| 137 | $count = $auth->getUserCount(array('user' => $user['user'])); |
||
| 138 | $this->assertGreaterThanOrEqual(1, $count); |
||
| 139 | $count = $auth->getUserCount(array('name' => $user['name'])); |
||
| 140 | $this->assertGreaterThanOrEqual(1, $count); |
||
| 141 | $count = $auth->getUserCount(array('mail' => $user['mail'])); |
||
| 142 | $this->assertGreaterThanOrEqual(1, $count); |
||
| 143 | } |
||
| 144 | |||
| 145 | // modPass |
||
| 146 | if($auth->canDo('modPass')) { |
||
| 147 | $newpass = 'foobar'; |
||
| 148 | $ok = $auth->modifyUser($user['user'], array('pass' => $newpass)); |
||
| 149 | $this->assertTrue($ok, $info); |
||
| 150 | $this->assertTrue($auth->checkPass($user['user'], $newpass), $info); |
||
| 151 | } |
||
| 152 | |||
| 153 | // modMail |
||
| 154 | if($auth->canDo('modMail')) { |
||
| 155 | $newmail = '[email protected]'; |
||
| 156 | $ok = $auth->modifyUser($user['user'], array('mail' => $newmail)); |
||
| 157 | $this->assertTrue($ok, $info); |
||
| 158 | $check = $auth->getUserData($user['user']); |
||
| 159 | $this->assertEquals($newmail, $check['mail'], $info); |
||
| 160 | } |
||
| 161 | |||
| 162 | // modName |
||
| 163 | if($auth->canDo('modName')) { |
||
| 164 | $newname = 'FirstName Foobar'; |
||
| 165 | $ok = $auth->modifyUser($user['user'], array('name' => $newname)); |
||
| 166 | $this->assertTrue($ok, $info); |
||
| 167 | $check = $auth->getUserData($user['user']); |
||
| 168 | $this->assertEquals($newname, $check['name'], $info); |
||
| 169 | } |
||
| 170 | |||
| 171 | // modLogin |
||
| 172 | if($auth->canDo('modLogin')) { |
||
| 173 | $newuser = 'foobar' . $user['user']; |
||
| 174 | $ok = $auth->modifyUser($user['user'], array('user' => $newuser)); |
||
| 175 | $this->assertTrue($ok, $info); |
||
| 176 | $check = $auth->getUserData($newuser); |
||
| 177 | $this->assertEquals($newuser, $check['user'], $info); |
||
| 178 | } |
||
| 179 | |||
| 180 | } |
||
| 181 | |||
| 220 |
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.