Conditions | 9 |
Paths | 96 |
Total Lines | 75 |
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 |
||
60 | function create_account_form($teamid, $next_url) { |
||
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 | if (USER_COUNTRY) { |
||
106 | form_select( |
||
107 | sprintf('<span title="%s">%s</span>', |
||
108 | tra("Select the country you want to represent, if any."), |
||
109 | tra("Country") |
||
110 | ), |
||
111 | "country", |
||
112 | country_select_options() |
||
113 | ); |
||
114 | } |
||
115 | if (POSTAL_CODE) { |
||
116 | form_input_text( |
||
117 | tra("Postal or ZIP Code")."<br><small>".tra("Optional")."</small>", |
||
118 | "postal_code" |
||
119 | ); |
||
120 | } |
||
121 | |||
122 | // Add terms of use to Web form. User must agree by checking the checkbox. |
||
123 | list($checkct, $ctid) = check_consent_type(CONSENT_TYPE_ENROLL); |
||
124 | if ($checkct and check_termsofuse()) { |
||
|
|||
125 | $terms_of_use = trim(file_get_contents(TERMSOFUSE_FILE)); |
||
126 | if ($terms_of_use) { |
||
127 | panel(tra('Terms of Use'), function() use($terms_of_use) { |
||
128 | echo nl2br($terms_of_use); |
||
129 | } |
||
130 | ); |
||
131 | $myitems = array( |
||
132 | array("agree_to_terms_of_use", "", false), |
||
133 | ); |
||
134 | form_checkboxes(tra("Do you agree to the terms of use above?"), $myitems, 'tabindex="0"'); |
||
135 | } |
||
189 |
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
die
introduces 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 withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.