| Conditions | 12 |
| Paths | 56 |
| Total Lines | 78 |
| Code Lines | 61 |
| Lines | 30 |
| Ratio | 38.46 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 117 | function productheader($area, $language) { |
||
| 118 | // this <div is closing in footer, keep it in PHP for Netbeans syntax |
||
| 119 | // highlighting to work |
||
| 120 | echo "<div class='maincontent'>"; |
||
| 121 | |||
| 122 | switch ($area) { |
||
| 123 | View Code Duplication | case "ADMIN-IDP": |
|
| 124 | $cap1 = Config::$APPEARANCE['productname_long']; |
||
| 125 | $cap2 = _("Administrator Interface - Identity Provider"); |
||
| 126 | $advanced_controls = TRUE; |
||
| 127 | break; |
||
| 128 | View Code Duplication | case "ADMIN": |
|
| 129 | $cap1 = Config::$APPEARANCE['productname_long']; |
||
| 130 | $cap2 = _("Administrator Interface"); |
||
| 131 | $advanced_controls = TRUE; |
||
| 132 | break; |
||
| 133 | View Code Duplication | case "USERMGMT": |
|
| 134 | $cap1 = Config::$APPEARANCE['productname_long']; |
||
| 135 | $cap2 = _("Management of User Details"); |
||
| 136 | $advanced_controls = TRUE; |
||
| 137 | break; |
||
| 138 | View Code Duplication | case "FEDERATION": |
|
| 139 | $cap1 = Config::$APPEARANCE['productname_long']; |
||
| 140 | $cap2 = _("Administrator Interface - Federation Management"); |
||
| 141 | $advanced_controls = TRUE; |
||
| 142 | break; |
||
| 143 | View Code Duplication | case "USER": |
|
| 144 | $cap1 = sprintf(_("Welcome to %s"), Config::$APPEARANCE['productname']); |
||
| 145 | $cap2 = Config::$APPEARANCE['productname_long']; |
||
| 146 | $advanced_controls = FALSE; |
||
| 147 | break; |
||
| 148 | View Code Duplication | case "SUPERADMIN": |
|
| 149 | $cap1 = Config::$APPEARANCE['productname_long']; |
||
| 150 | $cap2 = _("CIC"); |
||
| 151 | $advanced_controls = TRUE; |
||
| 152 | break; |
||
| 153 | default: |
||
| 154 | $cap1 = Config::$APPEARANCE['productname_long']; |
||
| 155 | $cap2 = "It is an error if you ever see this string."; |
||
| 156 | } |
||
| 157 | |||
| 158 | |||
| 159 | echo headerDiv($cap1); |
||
| 160 | // content from here on will SCROLL instead of being fixed at the top |
||
| 161 | echo "<div class='pagecontent'>"; // closes in footer again |
||
| 162 | echo "<div class='trick'>"; // closes in footer again |
||
| 163 | ?> |
||
| 164 | <div id='secondrow' style='border-bottom:5px solid <?php echo Config::$APPEARANCE['colour1']; ?>; min-height:100px;'> |
||
| 165 | <div id='secondarycaptions' style='display:inline-block; float:left'> |
||
| 166 | <h2><?php echo $cap2; ?></h2> |
||
| 167 | </div><!--secondarycaptions-->"; |
||
| 168 | <?php |
||
| 169 | if (isset(Config::$APPEARANCE['MOTD']) && Config::$APPEARANCE['MOTD'] != "") { |
||
| 170 | echo "<div id='header_MOTD' style='display:inline-block; padding-left:20px;vertical-align:top;'> |
||
| 171 | <p class='MOTD'>" . Config::$APPEARANCE['MOTD'] . "</p> |
||
| 172 | </div><!--header_MOTD-->"; |
||
| 173 | } |
||
| 174 | ?> |
||
| 175 | <div class='sidebar'><p> |
||
| 176 | <?php |
||
| 177 | if ($advanced_controls) { |
||
| 178 | echo "<strong>" . _("You are:") . "</strong> " |
||
| 179 | . (isset($_SESSION['name']) ? $_SESSION['name'] : _("Unnamed User")) . " |
||
| 180 | <br/> |
||
| 181 | <br/> |
||
| 182 | <a href='overview_user.php'>" . _("Go to your Profile page") . "</a> |
||
| 183 | <a href='inc/logout.php'>" . _("Logout") . "</a> "; |
||
| 184 | } |
||
| 185 | if (strpos($_SERVER['PHP_SELF'], "admin/") === FALSE) |
||
| 186 | echo "<a href='" . dirname($_SERVER['SCRIPT_NAME']) . "/'>" . _("Start page") . "</a>"; |
||
| 187 | else |
||
| 188 | echo "<a href='../'>" . _("Start page") . "</a>"; |
||
| 189 | ?> |
||
| 190 | </p> |
||
| 191 | </div> <!-- sidebar --> |
||
| 192 | </div><!--secondrow--> |
||
| 193 | <?php |
||
| 194 | } |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.