| Conditions | 11 |
| Paths | 46 |
| Total Lines | 99 |
| 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 |
||
| 94 | function sendfile() |
||
| 95 | { |
||
| 96 | global $conf; |
||
| 97 | |||
| 98 | $errorlevel=error_reporting(); |
||
| 99 | error_reporting($errorlevel ^ E_WARNING); // Desactive warnings |
||
| 100 | |||
| 101 | $res=false; |
||
| 102 | |||
| 103 | dol_syslog("CSMSFile::sendfile addr_to=".$this->addr_to, LOG_DEBUG); |
||
| 104 | dol_syslog("CSMSFile::sendfile message=\n".$this->message); |
||
| 105 | |||
| 106 | $this->message=stripslashes($this->message); |
||
| 107 | |||
| 108 | if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms(); |
||
| 109 | |||
| 110 | if (empty($conf->global->MAIN_DISABLE_ALL_SMS)) |
||
| 111 | { |
||
| 112 | |||
| 113 | // Action according to choosed sending method |
||
| 114 | if ($conf->global->MAIN_SMS_SENDMODE == 'ovh') // Backward compatibility @deprecated |
||
| 115 | { |
||
| 116 | dol_include_once('/ovh/class/ovhsms.class.php'); |
||
| 117 | $sms=new OvhSms($this->db); |
||
| 118 | $sms->expe=$this->addr_from; |
||
| 119 | $sms->dest=$this->addr_to; |
||
| 120 | $sms->message=$this->message; |
||
| 121 | $sms->deferred=$this->deferred; |
||
| 122 | $sms->priority=$this->priority; |
||
| 123 | $sms->class=$this->class; |
||
| 124 | $sms->nostop=$this->nostop; |
||
| 125 | |||
| 126 | $res=$sms->SmsSend(); |
||
| 127 | if ($res <= 0) |
||
| 128 | { |
||
| 129 | $this->error=$sms->error; |
||
| 130 | dol_syslog("CSMSFile::sendfile: sms send error=".$this->error, LOG_ERR); |
||
| 131 | } |
||
| 132 | else |
||
| 133 | { |
||
| 134 | dol_syslog("CSMSFile::sendfile: sms send success with id=".$res, LOG_DEBUG); |
||
| 135 | //var_dump($res); // 1973128 |
||
| 136 | if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res); |
||
| 137 | } |
||
| 138 | } |
||
| 139 | else if (! empty($conf->global->MAIN_SMS_SENDMODE)) // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module' |
||
| 140 | { |
||
| 141 | $tmp=explode('@',$conf->global->MAIN_SMS_SENDMODE); |
||
| 142 | $classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]); |
||
| 143 | dol_include_once('/'.$module.'/class/'.$classfile.'.class.php'); |
||
| 144 | try |
||
| 145 | { |
||
| 146 | $classname=ucfirst($classfile); |
||
| 147 | $sms = new $classname($this->db); |
||
| 148 | $sms->expe=$this->addr_from; |
||
| 149 | $sms->dest=$this->addr_to; |
||
| 150 | $sms->deferred=$this->deferred; |
||
| 151 | $sms->priority=$this->priority; |
||
| 152 | $sms->class=$this->class; |
||
| 153 | $sms->message=$this->message; |
||
| 154 | $sms->nostop=$this->nostop; |
||
| 155 | |||
| 156 | $res=$sms->SmsSend(); |
||
| 157 | $this->error = $sms->error; |
||
| 158 | $this->errors = $sms->errors; |
||
| 159 | if ($res <= 0) |
||
| 160 | { |
||
| 161 | dol_syslog("CSMSFile::sendfile: sms send error=".$this->error, LOG_ERR); |
||
| 162 | } |
||
| 163 | else |
||
| 164 | { |
||
| 165 | dol_syslog("CSMSFile::sendfile: sms send success with id=".$res, LOG_DEBUG); |
||
| 166 | //var_dump($res); // 1973128 |
||
| 167 | if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res); |
||
| 168 | } |
||
| 169 | } |
||
| 170 | catch(Exception $e) |
||
| 171 | { |
||
| 172 | dol_print_error('','Error to get list of senders: '.$e->getMessage()); |
||
| 173 | } |
||
| 174 | } |
||
| 175 | else |
||
| 176 | { |
||
| 177 | // Send sms method not correctly defined |
||
| 178 | // -------------------------------------- |
||
| 179 | |||
| 180 | return 'Bad value for MAIN_SMS_SENDMODE constant'; |
||
| 181 | } |
||
| 182 | } |
||
| 183 | else |
||
| 184 | { |
||
| 185 | $this->error='No sms sent. Feature is disabled by option MAIN_DISABLE_ALL_SMS'; |
||
| 186 | dol_syslog("CSMSFile::sendfile: ".$this->error, LOG_WARNING); |
||
| 187 | } |
||
| 188 | |||
| 189 | error_reporting($errorlevel); // Reactive niveau erreur origine |
||
| 190 | |||
| 191 | return $res; |
||
| 192 | } |
||
| 193 | |||
| 250 |