| Conditions | 21 |
| Paths | 16875 |
| Total Lines | 59 |
| Code Lines | 32 |
| 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 |
||
| 143 | function html_print_stripe_footer($fromcompany,$langs) |
||
| 144 | { |
||
| 145 | global $conf; |
||
| 146 | |||
| 147 | // Juridical status |
||
| 148 | $line1=""; |
||
| 149 | if ($fromcompany->forme_juridique_code) |
||
| 150 | { |
||
| 151 | $line1.=($line1?" - ":"").getFormeJuridiqueLabel($fromcompany->forme_juridique_code); |
||
| 152 | } |
||
| 153 | // Capital |
||
| 154 | if ($fromcompany->capital) |
||
| 155 | { |
||
| 156 | $line1.=($line1?" - ":"").$langs->transnoentities("CapitalOf",$fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency); |
||
| 157 | } |
||
| 158 | // Prof Id 1 |
||
| 159 | if ($fromcompany->idprof1 && ($fromcompany->country_code != 'FR' || ! $fromcompany->idprof2)) |
||
| 160 | { |
||
| 161 | $field=$langs->transcountrynoentities("ProfId1",$fromcompany->country_code); |
||
| 162 | if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1]; |
||
| 163 | $line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof1; |
||
| 164 | } |
||
| 165 | // Prof Id 2 |
||
| 166 | if ($fromcompany->idprof2) |
||
| 167 | { |
||
| 168 | $field=$langs->transcountrynoentities("ProfId2",$fromcompany->country_code); |
||
| 169 | if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1]; |
||
| 170 | $line1.=($line1?" - ":"").$field.": ".$fromcompany->idprof2; |
||
| 171 | } |
||
| 172 | |||
| 173 | // Second line of company infos |
||
| 174 | $line2=""; |
||
| 175 | // Prof Id 3 |
||
| 176 | if ($fromcompany->idprof3) |
||
| 177 | { |
||
| 178 | $field=$langs->transcountrynoentities("ProfId3",$fromcompany->country_code); |
||
| 179 | if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1]; |
||
| 180 | $line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof3; |
||
| 181 | } |
||
| 182 | // Prof Id 4 |
||
| 183 | if ($fromcompany->idprof4) |
||
| 184 | { |
||
| 185 | $field=$langs->transcountrynoentities("ProfId4",$fromcompany->country_code); |
||
| 186 | if (preg_match('/\((.*)\)/i',$field,$reg)) $field=$reg[1]; |
||
| 187 | $line2.=($line2?" - ":"").$field.": ".$fromcompany->idprof4; |
||
| 188 | } |
||
| 189 | // IntraCommunautary VAT |
||
| 190 | if ($fromcompany->tva_intra != '') |
||
| 191 | { |
||
| 192 | $line2.=($line2?" - ":"").$langs->transnoentities("VATIntraShort").": ".$fromcompany->tva_intra; |
||
| 193 | } |
||
| 194 | |||
| 195 | print '<br><br><hr>'."\n"; |
||
| 196 | print '<div class="center"><font style="font-size: 10px;">'."\n"; |
||
| 197 | print $fromcompany->name.'<br>'; |
||
| 198 | print $line1.'<br>'; |
||
| 199 | print $line2; |
||
| 200 | print '</font></div>'."\n"; |
||
| 201 | } |
||
| 202 | |||
| 203 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: