| Conditions | 36 |
| Paths | 16800 |
| Total Lines | 210 |
| Code Lines | 143 |
| Lines | 5 |
| Ratio | 2.38 % |
| 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 |
||
| 47 | public function doDefault($msg = '') |
||
| 48 | { |
||
| 49 | $conf = $this->conf; |
||
| 50 | $misc = $this->misc; |
||
| 51 | $lang = $this->lang; |
||
| 52 | $action = $this->action; |
||
| 53 | $data = $misc->getDatabaseAccessor(); |
||
| 54 | $database = $misc->getDatabase(); |
||
| 55 | |||
| 56 | $this->printTrail($_REQUEST['subject']); |
||
| 57 | |||
| 58 | # @@@FIXME: This switch is just a temporary solution, |
||
| 59 | # need a better way, maybe every type of object should |
||
| 60 | # have a tab bar??? |
||
| 61 | switch ($_REQUEST['subject']) { |
||
| 62 | case 'server': |
||
| 63 | case 'database': |
||
| 64 | case 'schema': |
||
| 65 | case 'table': |
||
| 66 | case 'column': |
||
| 67 | case 'view': |
||
| 68 | $this->printTabs($_REQUEST['subject'], 'privileges'); |
||
| 69 | break; |
||
| 70 | default: |
||
| 71 | $this->printTitle($lang['strprivileges'], 'pg.privilege'); |
||
| 72 | } |
||
| 73 | $this->printMsg($msg); |
||
| 74 | |||
| 75 | // Determine whether object should be ref'd by name or oid. |
||
| 76 | View Code Duplication | if (isset($_REQUEST[$_REQUEST['subject'] . '_oid'])) { |
|
| 77 | $object = $_REQUEST[$_REQUEST['subject'] . '_oid']; |
||
| 78 | } else { |
||
| 79 | $object = $_REQUEST[$_REQUEST['subject']]; |
||
| 80 | } |
||
| 81 | |||
| 82 | // Get the privileges on the object, given its type |
||
| 83 | if ($_REQUEST['subject'] == 'column') { |
||
| 84 | $privileges = $data->getPrivileges($object, 'column', $_REQUEST['table']); |
||
| 85 | } else { |
||
| 86 | $privileges = $data->getPrivileges($object, $_REQUEST['subject']); |
||
| 87 | } |
||
| 88 | |||
| 89 | if (sizeof($privileges) > 0) { |
||
| 90 | echo "<table>\n"; |
||
| 91 | if ($data->hasRoles()) { |
||
| 92 | echo "<tr><th class=\"data\">{$lang['strrole']}</th>"; |
||
| 93 | } else { |
||
| 94 | echo "<tr><th class=\"data\">{$lang['strtype']}</th><th class=\"data\">{$lang['struser']}/{$lang['strgroup']}</th>"; |
||
| 95 | } |
||
| 96 | |||
| 97 | foreach ($data->privlist[$_REQUEST['subject']] as $v2) { |
||
| 98 | // Skip over ALL PRIVILEGES |
||
| 99 | if ($v2 == 'ALL PRIVILEGES') { |
||
| 100 | continue; |
||
| 101 | } |
||
| 102 | |||
| 103 | echo "<th class=\"data\">{$v2}</th>\n"; |
||
| 104 | } |
||
| 105 | if ($data->hasGrantOption()) { |
||
| 106 | echo "<th class=\"data\">{$lang['strgrantor']}</th>"; |
||
| 107 | } |
||
| 108 | echo "</tr>\n"; |
||
| 109 | |||
| 110 | // Loop over privileges, outputting them |
||
| 111 | $i = 0; |
||
| 112 | foreach ($privileges as $v) { |
||
| 113 | $id = (($i % 2) == 0 ? '1' : '2'); |
||
| 114 | echo "<tr class=\"data{$id}\">\n"; |
||
| 115 | if (!$data->hasRoles()) { |
||
| 116 | echo '<td>', $misc->printVal($v[0]), "</td>\n"; |
||
| 117 | } |
||
| 118 | |||
| 119 | echo '<td>', $misc->printVal($v[1]), "</td>\n"; |
||
| 120 | foreach ($data->privlist[$_REQUEST['subject']] as $v2) { |
||
| 121 | // Skip over ALL PRIVILEGES |
||
| 122 | if ($v2 == 'ALL PRIVILEGES') { |
||
| 123 | continue; |
||
| 124 | } |
||
| 125 | |||
| 126 | echo '<td>'; |
||
| 127 | if (in_array($v2, $v[2])) { |
||
| 128 | echo $lang['stryes']; |
||
| 129 | } else { |
||
| 130 | echo $lang['strno']; |
||
| 131 | } |
||
| 132 | |||
| 133 | // If we have grant option for this, end mark |
||
| 134 | if ($data->hasGrantOption() && in_array($v2, $v[4])) { |
||
| 135 | echo $lang['strasterisk']; |
||
| 136 | } |
||
| 137 | |||
| 138 | echo "</td>\n"; |
||
| 139 | } |
||
| 140 | if ($data->hasGrantOption()) { |
||
| 141 | echo '<td>', $misc->printVal($v[3]), "</td>\n"; |
||
| 142 | } |
||
| 143 | echo "</tr>\n"; |
||
| 144 | $i++; |
||
| 145 | } |
||
| 146 | |||
| 147 | echo '</table>'; |
||
| 148 | } else { |
||
| 149 | echo "<p>{$lang['strnoprivileges']}</p>\n"; |
||
| 150 | } |
||
| 151 | |||
| 152 | // Links for granting to a user or group |
||
| 153 | switch ($_REQUEST['subject']) { |
||
| 154 | case 'table': |
||
| 155 | case 'view': |
||
| 156 | case 'sequence': |
||
| 157 | case 'function': |
||
| 158 | case 'tablespace': |
||
| 159 | $alllabel = "showall{$_REQUEST['subject']}s"; |
||
| 160 | $allurl = "{$_REQUEST['subject']}s.php"; |
||
| 161 | $alltxt = $lang["strshowall{$_REQUEST['subject']}s"]; |
||
| 162 | break; |
||
| 163 | case 'schema': |
||
| 164 | $alllabel = 'showallschemas'; |
||
| 165 | $allurl = 'schemas.php'; |
||
| 166 | $alltxt = $lang['strshowallschemas']; |
||
| 167 | break; |
||
| 168 | case 'database': |
||
| 169 | $alllabel = 'showalldatabases'; |
||
| 170 | $allurl = 'alldb.php'; |
||
| 171 | $alltxt = $lang['strshowalldatabases']; |
||
| 172 | break; |
||
| 173 | } |
||
| 174 | |||
| 175 | $subject = $_REQUEST['subject']; |
||
| 176 | $object = $_REQUEST[$_REQUEST['subject']]; |
||
| 177 | |||
| 178 | if ($_REQUEST['subject'] == 'function') { |
||
| 179 | $objectoid = $_REQUEST[$_REQUEST['subject'] . '_oid']; |
||
| 180 | $urlvars = [ |
||
| 181 | 'action' => 'alter', |
||
| 182 | 'server' => $_REQUEST['server'], |
||
| 183 | 'database' => $_REQUEST['database'], |
||
| 184 | 'schema' => $_REQUEST['schema'], |
||
| 185 | $subject => $object, |
||
| 186 | "{$subject}_oid" => $objectoid, |
||
| 187 | 'subject' => $subject, |
||
| 188 | ]; |
||
| 189 | } elseif ($_REQUEST['subject'] == 'column') { |
||
| 190 | $urlvars = [ |
||
| 191 | 'action' => 'alter', |
||
| 192 | 'server' => $_REQUEST['server'], |
||
| 193 | 'database' => $_REQUEST['database'], |
||
| 194 | 'schema' => $_REQUEST['schema'], |
||
| 195 | $subject => $object, |
||
| 196 | 'subject' => $subject, |
||
| 197 | ]; |
||
| 198 | |||
| 199 | if (isset($_REQUEST['table'])) { |
||
| 200 | $urlvars['table'] = $_REQUEST['table']; |
||
| 201 | } else { |
||
| 202 | $urlvars['view'] = $_REQUEST['view']; |
||
| 203 | } |
||
| 204 | } else { |
||
| 205 | $urlvars = [ |
||
| 206 | 'action' => 'alter', |
||
| 207 | 'server' => $_REQUEST['server'], |
||
| 208 | 'database' => $_REQUEST['database'], |
||
| 209 | $subject => $object, |
||
| 210 | 'subject' => $subject, |
||
| 211 | ]; |
||
| 212 | if (isset($_REQUEST['schema'])) { |
||
| 213 | $urlvars['schema'] = $_REQUEST['schema']; |
||
| 214 | } |
||
| 215 | } |
||
| 216 | |||
| 217 | $navlinks = [ |
||
| 218 | 'grant' => [ |
||
| 219 | 'attr' => [ |
||
| 220 | 'href' => [ |
||
| 221 | 'url' => 'privileges.php', |
||
| 222 | 'urlvars' => array_merge($urlvars, ['mode' => 'grant']), |
||
| 223 | ], |
||
| 224 | ], |
||
| 225 | 'content' => $lang['strgrant'], |
||
| 226 | ], |
||
| 227 | 'revoke' => [ |
||
| 228 | 'attr' => [ |
||
| 229 | 'href' => [ |
||
| 230 | 'url' => 'privileges.php', |
||
| 231 | 'urlvars' => array_merge($urlvars, ['mode' => 'revoke']), |
||
| 232 | ], |
||
| 233 | ], |
||
| 234 | 'content' => $lang['strrevoke'], |
||
| 235 | ], |
||
| 236 | ]; |
||
| 237 | |||
| 238 | if (isset($allurl)) { |
||
| 239 | $navlinks[$alllabel] = [ |
||
| 240 | 'attr' => [ |
||
| 241 | 'href' => [ |
||
| 242 | 'url' => $allurl, |
||
| 243 | 'urlvars' => [ |
||
| 244 | 'server' => $_REQUEST['server'], |
||
| 245 | 'database' => $_REQUEST['database'], |
||
| 246 | ], |
||
| 247 | ], |
||
| 248 | ], |
||
| 249 | 'content' => $alltxt, |
||
| 250 | ]; |
||
| 251 | if (isset($_REQUEST['schema'])) { |
||
| 252 | $navlinks[$alllabel]['attr']['href']['urlvars']['schema'] = $_REQUEST['schema']; |
||
| 253 | } |
||
| 254 | } |
||
| 255 | |||
| 256 | $this->printNavLinks($navlinks, $this->table_place, get_defined_vars()); |
||
| 257 | } |
||
| 406 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: