Plugin::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace Helick\Mail;
4
5
use Helick\Contracts\Bootable;
6
use PHPMailer;
0 ignored issues
show
Bug introduced by
The type PHPMailer 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...
7
8
final class Plugin implements Bootable
9
{
10
    /**
11
     * Boot the service.
12
     *
13
     * @return void
14
     */
15
    public static function boot(): void
16
    {
17
        $self = new static;
18
19
        add_action('phpmailer_init', [$self, 'setup']);
0 ignored issues
show
Bug introduced by
The function add_action 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

19
        /** @scrutinizer ignore-call */ 
20
        add_action('phpmailer_init', [$self, 'setup']);
Loading history...
20
        add_filter('wp_mail_from_name', [$self, 'fromName']);
0 ignored issues
show
Bug introduced by
The function add_filter 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

20
        /** @scrutinizer ignore-call */ 
21
        add_filter('wp_mail_from_name', [$self, 'fromName']);
Loading history...
21
        add_filter('wp_mail_from', [$self, 'fromAddress']);
22
    }
23
24
    /**
25
     * Setup the SMTP connection.
26
     *
27
     * @param PHPMailer $mailer
28
     *
29
     * @return void
30
     */
31
    public function setup(PHPMailer $mailer): void
32
    {
33
        $mailer->isSMTP();
34
        $mailer->SMTPAuth = true;
35
36
        $mailer->Host     = host();
37
        $mailer->Port     = port();
38
        $mailer->Username = user();
39
        $mailer->Password = password();
40
    }
41
42
    /**
43
     * Setup "From Name" header.
44
     *
45
     * @return string
46
     */
47
    public function fromName(): string
48
    {
49
        return from_name();
50
    }
51
52
    /**
53
     * Setup "From Address" header.
54
     *
55
     * @return string
56
     */
57
    public function fromAddress(): string
58
    {
59
        return from_address();
60
    }
61
}
62