Passed
Push — master ( f39060...11ca94 )
by Joe Nilson
02:13
created

ResidentesEnviarMail::emailAdditionalInfo()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 12
rs 9.9666
1
<?php
2
/*
3
 * Copyright (C) 2021 Joe Nilson <[email protected]>
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Lesser General Public License as
7
 * published by the Free Software Foundation, either version 3 of the
8
 * License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU Lesser General Public License for more details.
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
require_once 'extras/phpmailer/class.phpmailer.php';
19
require_once 'extras/phpmailer/class.smtp.php';
20
21
class ResidentesEnviarMail
22
{
23
    public $log;
24
    public $rc;
25
    public function __construct()
26
    {
27
        $this->log = new fs_core_log();
0 ignored issues
show
Bug introduced by
The type fs_core_log was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
        $this->rc = new residentes_controller();
29
    }
30
31
    public function invoiceEmail(&$companyInformation, &$invoice, &$customer, $user, $archivo)
32
    {
33
        if (file_exists('tmp/'.FS_TMP_NAME.'enviar/'.$archivo)) {
34
            $mail = $companyInformation->new_mail();
35
            $mail->FromName = (is_object($user)) ? $user->get_agente_fullname() : $companyInformation->nombre;
36
            $email = $customer->email;
37
            $this->log->new_message('Enviando factura a: '.$email);
38
            $mail->addAddress($email, $customer->nombre);
39
            $elSubject = ' - Su Factura ' . $invoice->codigo . ' ' . $invoice->numero2;
40
            $mail->Subject = fs_fix_html($companyInformation->nombre) . $elSubject;
41
            $mail->AltBody = plantilla_email(
0 ignored issues
show
Bug introduced by
The function plantilla_email was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
            $mail->AltBody = /** @scrutinizer ignore-call */ plantilla_email(
Loading history...
42
                'factura',
43
                $invoice->codigo . ' ' . $invoice->numero2,
44
                $companyInformation->email_config['mail_firma']
45
            );
46
            $this->emailAdditionalInfo($mail, $customer);
47
            $mail->msgHTML(nl2br($mail->AltBody));
48
            $mail->isHTML(true);
49
            $mail->addAttachment('tmp/' . FS_TMP_NAME . 'enviar/' . $archivo);
50
            $this->emailAdditionalAttachments($mail);
51
            if ($companyInformation->mail_connect($mail) && $mail->send()) {
52
                $invoice->femail = \date('d-m-Y');;
53
                $invoice->save();
54
                $companyInformation->save_mail($mail);
55
            } else {
56
                $this->log->new_error_msg("Error al enviar el email: " . $mail->ErrorInfo);
57
            }
58
            unlink('tmp/' . FS_TMP_NAME . 'enviar/' . $archivo);
59
        } else {
60
            $this->log->new_error_msg('Imposible generar el PDF.');
61
        }
62
    }
63
64
    public function emailAdditionalInfo(&$mail, $customer)
65
    {
66
        if (trim($this->rc->filter_request('email_copia')) !== '') {
0 ignored issues
show
Bug introduced by
It seems like $this->rc->filter_request('email_copia') can also be of type boolean; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

66
        if (trim(/** @scrutinizer ignore-type */ $this->rc->filter_request('email_copia')) !== '') {
Loading history...
67
            if ($this->rc->filter_request('cco') !== null) {
0 ignored issues
show
introduced by
The condition $this->rc->filter_request('cco') !== null is always true.
Loading history...
68
                $mail->addBCC(
69
                    trim($this->rc->filter_request('email_copia')),
70
                    $customer->nombre
71
                );
72
            } else {
73
                $mail->addCC(
74
                    trim($this->rc->filter_request('email_copia')),
75
                    $customer->nombre
76
                );
77
            }
78
        }
79
    }
80
81
    public function emailAdditionalAttachments(&$mail)
82
    {
83
        if (isset($_FILES['adjunto']) && is_uploaded_file($_FILES['adjunto']['tmp_name'])) {
84
            $mail->addAttachment($_FILES['adjunto']['tmp_name'], $_FILES['adjunto']['name']);
85
        }
86
    }
87
88
    public function accountStatusEmail(&$empresa, &$customer, $user, $archivo)
89
    {
90
        $mail = $empresa->new_mail();
91
        $mail->FromName = (is_object($user)) ? $user->get_agente_fullname() : $empresa->nombre;
92
        $email = (trim($this->rc->filter_request('email')) !== '')
0 ignored issues
show
Bug introduced by
It seems like $this->rc->filter_request('email') can also be of type boolean; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

92
        $email = (trim(/** @scrutinizer ignore-type */ $this->rc->filter_request('email')) !== '')
Loading history...
93
            ? $this->rc->filter_request('email')
94
            : $customer->email;
95
        $this->log->new_message('Enviando Estado de cuenta a: '.$email);
96
        $mail->addAddress($email, $customer->nombre);
97
        $elSubject = ': Su Estado de cuenta al '. \date('d-m-Y');
98
        $mail->Subject = fs_fix_html($empresa->nombre) . $elSubject;
99
        $mail->AltBody = strip_tags($_POST['mensaje']);
100
        $this->emailAdditionalAttachments($mail);
101
        $mail->msgHTML(nl2br($mail->AltBody));
102
        $mail->isHTML(true);
103
        $mail->addAttachment('tmp/' . FS_TMP_NAME . 'enviar/' . $archivo);
104
        $this->emailAdditionalAttachments($mail);
105
        if ($empresa->mail_connect($mail) && $mail->send()) {
106
            $empresa->save_mail($mail);
107
        } else {
108
            $this->log->new_error_msg("Error al enviar el email: " . $mail->ErrorInfo);
109
        }
110
        unlink('tmp/' . FS_TMP_NAME . 'enviar/' . $archivo);
111
    }
112
}