| Conditions | 52 |
| Paths | > 20000 |
| Total Lines | 93 |
| Code Lines | 58 |
| 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 |
||
| 124 | function getOnlinePaymentUrl($mode,$type,$ref='',$amount='9.99',$freetag='your_free_tag') |
||
| 125 | { |
||
| 126 | global $conf; |
||
| 127 | |||
| 128 | $ref=str_replace(' ','',$ref); |
||
| 129 | |||
| 130 | if ($type == 'free') |
||
| 131 | { |
||
| 132 | $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?amount='.($mode?'<font color="#666666">':'').$amount.($mode?'</font>':'').'&tag='.($mode?'<font color="#666666">':'').$freetag.($mode?'</font>':''); |
||
| 133 | if (! empty($conf->global->PAYMENT_SECURITY_TOKEN)) |
||
| 134 | { |
||
| 135 | if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN; |
||
| 136 | else $out.='&securekey='.dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2); |
||
| 137 | } |
||
| 138 | } |
||
| 139 | if ($type == 'order') |
||
| 140 | { |
||
| 141 | $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?source=order&ref='.($mode?'<font color="#666666">':''); |
||
| 142 | if ($mode == 1) $out.='order_ref'; |
||
| 143 | if ($mode == 0) $out.=urlencode($ref); |
||
| 144 | $out.=($mode?'</font>':''); |
||
| 145 | if (! empty($conf->global->PAYMENT_SECURITY_TOKEN)) |
||
| 146 | { |
||
| 147 | if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN; |
||
| 148 | else |
||
| 149 | { |
||
| 150 | $out.='&securekey='.($mode?'<font color="#666666">':''); |
||
| 151 | if ($mode == 1) $out.="hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + order_ref)"; |
||
| 152 | if ($mode == 0) $out.= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . $type . $ref, 2); |
||
| 153 | $out.=($mode?'</font>':''); |
||
| 154 | } |
||
| 155 | } |
||
| 156 | } |
||
| 157 | if ($type == 'invoice') |
||
| 158 | { |
||
| 159 | $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?source=invoice&ref='.($mode?'<font color="#666666">':''); |
||
| 160 | if ($mode == 1) $out.='invoice_ref'; |
||
| 161 | if ($mode == 0) $out.=urlencode($ref); |
||
| 162 | $out.=($mode?'</font>':''); |
||
| 163 | if (! empty($conf->global->PAYMENT_SECURITY_TOKEN)) |
||
| 164 | { |
||
| 165 | if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN; |
||
| 166 | else |
||
| 167 | { |
||
| 168 | $out.='&securekey='.($mode?'<font color="#666666">':''); |
||
| 169 | if ($mode == 1) $out.="hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + invoice_ref)"; |
||
| 170 | if ($mode == 0) $out.= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . $type . $ref, 2); |
||
| 171 | $out.=($mode?'</font>':''); |
||
| 172 | } |
||
| 173 | } |
||
| 174 | } |
||
| 175 | if ($type == 'contractline') |
||
| 176 | { |
||
| 177 | $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?source=contractline&ref='.($mode?'<font color="#666666">':''); |
||
| 178 | if ($mode == 1) $out.='contractline_ref'; |
||
| 179 | if ($mode == 0) $out.=urlencode($ref); |
||
| 180 | $out.=($mode?'</font>':''); |
||
| 181 | if (! empty($conf->global->PAYMENT_SECURITY_TOKEN)) |
||
| 182 | { |
||
| 183 | if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN; |
||
| 184 | else |
||
| 185 | { |
||
| 186 | $out.='&securekey='.($mode?'<font color="#666666">':''); |
||
| 187 | if ($mode == 1) $out.="hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + contractline_ref)"; |
||
| 188 | if ($mode == 0) $out.= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . $type . $ref, 2); |
||
| 189 | $out.=($mode?'</font>':''); |
||
| 190 | } |
||
| 191 | } |
||
| 192 | } |
||
| 193 | if ($type == 'membersubscription') |
||
| 194 | { |
||
| 195 | $out=DOL_MAIN_URL_ROOT.'/public/payment/newpayment.php?source=membersubscription&ref='.($mode?'<font color="#666666">':''); |
||
| 196 | if ($mode == 1) $out.='member_ref'; |
||
| 197 | if ($mode == 0) $out.=urlencode($ref); |
||
| 198 | $out.=($mode?'</font>':''); |
||
| 199 | if (! empty($conf->global->PAYMENT_SECURITY_TOKEN)) |
||
| 200 | { |
||
| 201 | if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) $out.='&securekey='.$conf->global->PAYMENT_SECURITY_TOKEN; |
||
| 202 | else |
||
| 203 | { |
||
| 204 | $out.='&securekey='.($mode?'<font color="#666666">':''); |
||
| 205 | if ($mode == 1) $out.="hash('".$conf->global->PAYMENT_SECURITY_TOKEN."' + '".$type."' + member_ref)"; |
||
| 206 | if ($mode == 0) $out.= dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . $type . $ref, 2); |
||
| 207 | $out.=($mode?'</font>':''); |
||
| 208 | } |
||
| 209 | } |
||
| 210 | } |
||
| 211 | |||
| 212 | // For multicompany |
||
| 213 | $out.="&entity=".$conf->entity; // Check the entity because He may be the same reference in several entities |
||
| 214 | |||
| 215 | return $out; |
||
| 216 | } |
||
| 217 | |||
| 311 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.