| Conditions | 8 |
| Paths | 48 |
| Total Lines | 74 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 59 | function create_account_form($teamid, $next_url) { |
||
| 60 | global $recaptcha_public_key; |
||
| 61 | form_input_hidden('next_url', $next_url); |
||
| 62 | |||
| 63 | if ($teamid) { |
||
| 64 | form_input_hidden('teamid', $teamid); |
||
| 65 | } |
||
| 66 | |||
| 67 | // Using invitation codes to restrict access? |
||
| 68 | // |
||
| 69 | if (defined('INVITE_CODES')) { |
||
| 70 | form_input_text( |
||
| 71 | sprintf('<span title="%s">%s</span>', |
||
| 72 | tra("An invitation code is required to create an account."), |
||
| 73 | tra("Invitation code") |
||
| 74 | ), |
||
| 75 | "invite_code" |
||
| 76 | ); |
||
| 77 | } |
||
| 78 | |||
| 79 | form_input_text( |
||
| 80 | sprintf('<span title="%s">%s</span>', |
||
| 81 | tra("Identifies you on our web site. Use your real name or a nickname."), |
||
| 82 | tra("Screen name") |
||
| 83 | ), |
||
| 84 | "new_name" |
||
| 85 | ); |
||
| 86 | form_input_text( |
||
| 87 | sprintf('<span title="%s">%s</span>', |
||
| 88 | tra("Must be a valid address of the form 'name@domain'."), |
||
| 89 | tra("Email address") |
||
| 90 | ), |
||
| 91 | "new_email_addr" |
||
| 92 | ); |
||
| 93 | $min_passwd_length = parse_element(get_config(), "<min_passwd_length>"); |
||
| 94 | if (!$min_passwd_length) { |
||
| 95 | $min_passwd_length = 6; |
||
| 96 | } |
||
| 97 | |||
| 98 | form_input_text( |
||
| 99 | sprintf('<span title="%s">%s</span>', |
||
| 100 | tra("Must be at least %1 characters", $min_passwd_length), |
||
| 101 | tra("Password") |
||
| 102 | ), |
||
| 103 | "passwd", "", "password",'id="passwd"',passwd_visible_checkbox("passwd") |
||
| 104 | ); |
||
| 105 | form_select( |
||
| 106 | sprintf('<span title="%s">%s</span>', |
||
| 107 | tra("Select the country you want to represent, if any."), |
||
| 108 | tra("Country") |
||
| 109 | ), |
||
| 110 | "country", |
||
| 111 | country_select_options() |
||
| 112 | ); |
||
| 113 | if (POSTAL_CODE) { |
||
| 114 | form_input_text( |
||
| 115 | tra("Postal or ZIP Code")."<br><small>".tra("Optional")."</small>", |
||
| 116 | "postal_code" |
||
| 117 | ); |
||
| 118 | } |
||
| 119 | |||
| 120 | // Add terms of use to Web form. User must agree by checking the checkbox. |
||
| 121 | list($checkct, $ctid) = check_consent_type(CONSENT_TYPE_ENROLL); |
||
| 122 | if ($checkct and check_termsofuse()) { |
||
|
|
|||
| 123 | $terms_of_use = trim(file_get_contents(TERMSOFUSE_FILE)); |
||
| 124 | if ($terms_of_use) { |
||
| 125 | panel(tra('Terms of Use'), function() use($terms_of_use) { |
||
| 126 | echo nl2br($terms_of_use); |
||
| 127 | } |
||
| 128 | ); |
||
| 129 | $myitems = array( |
||
| 130 | array("agree_to_terms_of_use", "", false), |
||
| 131 | ); |
||
| 132 | form_checkboxes(tra("Do you agree to the terms of use above?"), $myitems, 'tabindex="0"'); |
||
| 133 | } |
||
| 187 |
PHP has two types of connecting operators (logical operators, and boolean operators):
and&&or||The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&, or||.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
dieintroduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrowat this point:These limitations lead to logical operators rarely being of use in current PHP code.