Test Failed
Push — master ( 892598...558941 )
by Antonio Carlos
11:17
created

Mail::check()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PragmaRX\Health\Checkers;
4
5
use PragmaRX\Health\Support\Result;
6
use Illuminate\Support\Facades\Mail as IlluminateMail;
7
8
class Mail extends Base
9
{
10
    /**
11
     * Store mail configuration.
12
     *
13
     * @var
14
     */
15
    private $mailConfiguration;
16
17
    /**
18
     * Check resource.
19
     *
20
     * @return Result
21
     */
22 1
    public function check()
23
    {
24 1
        return $this->checkMail();
25
    }
26
27
    /**
28
     * Configure mail for testing.
29
     */
30 1
    private function configureMail()
31
    {
32 1
        $this->mailConfiguration = config('mail');
33
34 1
        config(['mail' => $this->target->config->toArray()]);
0 ignored issues
show
Bug introduced by
The property config does not seem to exist in PragmaRX\Health\Support\Target.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
35 1
    }
36
37
    /**
38
     * Send a test e-mail.
39
     */
40 1
    private function checkMail()
41
    {
42 1
        $this->configureMail();
43
44
        try {
45 1
            $this->sendMail();
46
47 1
            $result = $this->makeHealthyResult();
48
        } catch (\Exception $exception) {
49
            report($exception);
50
51
            $result = $this->makeResultFromException($exception);
52
        }
53
54 1
        $this->restoreMailConfiguration();
55
56 1
        return $result;
57
    }
58
59
    /**
60
     * Restore mail configuration.
61
     */
62 1
    private function restoreMailConfiguration()
63
    {
64 1
        config(['mail' => $this->mailConfiguration]);
65 1
    }
66
67
    /**
68
     * Send a test e-mail message.
69
     */
70 1
    private function sendMail()
71
    {
72
        IlluminateMail::send($this->target->view, [], function ($message) {
0 ignored issues
show
Bug introduced by
The property view does not seem to exist in PragmaRX\Health\Support\Target.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
73 1
            $fromAddress = array_get($this->target->config, 'from.address');
0 ignored issues
show
Bug introduced by
The property config does not seem to exist in PragmaRX\Health\Support\Target.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
74
75 1
            $message->returnPath($fromAddress);
76
77 1
            $message->cc($fromAddress);
78
79 1
            $message->bcc($fromAddress);
80
81 1
            $message->replyTo($fromAddress);
82
83 1
            $message->to($this->target->to);
0 ignored issues
show
Bug introduced by
The property to does not seem to exist in PragmaRX\Health\Support\Target.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
84
85 1
            $message->subject($this->target->subject);
0 ignored issues
show
Bug introduced by
The property subject does not seem to exist in PragmaRX\Health\Support\Target.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
86 1
        });
87 1
    }
88
}
89