| Conditions | 9 |
| Paths | 7 |
| Total 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 |
||
| 79 | public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) |
||
| 80 | { |
||
| 81 | if (empty($conf->flightlog->enabled) || empty($conf->workflow->enabled)){ |
||
| 82 | return 0; |
||
| 83 | } |
||
| 84 | |||
| 85 | if(empty($conf->global->WORKFLOW_BBC_FLIGHTLOG_SEND_MAIL_ON_INCIDENT)){ |
||
| 86 | return 0; |
||
| 87 | } |
||
| 88 | |||
| 89 | if($action !== 'BBC_FLIGHT_LOG_ADD_FLIGHT'){ |
||
| 90 | return 0; |
||
| 91 | } |
||
| 92 | |||
| 93 | if(empty(trim($object->incidents)) && empty(trim($object->remarque))){ |
||
| 94 | return 0; |
||
| 95 | } |
||
| 96 | |||
| 97 | if(!empty($conf->global->MAIN_DISABLE_ALL_MAILS)){ |
||
| 98 | return 0; |
||
| 99 | } |
||
| 100 | |||
| 101 | $message = "<p>Bonjour,</p><br/>"; |
||
| 102 | $message .= sprintf("<p>Vous recevez cet e-mail car un vol a été encodé avec un incident/ une remarque sur le ballon : %s.</p>", $object->getBalloon()->immat); |
||
| 103 | $message .= sprintf("<p>Vol id : %d</p>", $object->getId()); |
||
| 104 | $message .= sprintf("<p>Réalisé par : %s </p>", $object->getPilot()->getFullName($langs)); |
||
| 105 | $message .= "<br/>"; |
||
| 106 | $message .= sprintf("<p>Commentaire : %s </p>", $object->getComment()); |
||
| 107 | $message .= sprintf("<p>Incident : %s </p>", $object->getIncident()); |
||
| 108 | $message .= "<p>Ce mail est un mail informatif automatique, il ne faut pas y répondre.</p>"; |
||
| 109 | $message .= "<p>Le Belgian balloon club.</p>"; |
||
| 110 | |||
| 111 | $responsable = new User($user->db); |
||
| 112 | $responsable->fetch($object->getBalloon()->fk_responsable); |
||
| 113 | |||
| 114 | $mailfile = new CMailFile( |
||
| 115 | sprintf("Un vol a été encodé avec un incident / un commentaire sur le ballon %s", $object->getBalloon()->immat), |
||
| 116 | $responsable->email, |
||
| 117 | $conf->global->MAIN_MAIL_EMAIL_FROM, |
||
| 118 | $message, |
||
| 119 | array(), |
||
| 120 | array(), |
||
| 121 | array(), |
||
| 122 | '', |
||
| 123 | '', |
||
| 124 | 0, |
||
| 125 | -1, |
||
| 126 | $conf->global->MAIN_MAIL_ERRORS_TO |
||
| 127 | ); |
||
| 128 | |||
| 129 | |||
| 130 | if (! $mailfile->sendfile()) |
||
| 131 | { |
||
| 132 | dol_syslog("Error while sending mail in flight log module : incident", LOG_ERR); |
||
| 133 | } |
||
| 134 | |||
| 135 | return 0; |
||
| 136 | } |
||
| 137 | } |
||
| 138 |