Completed
Push — master ( f33bf1...6be0b2 )
by Freek
01:44
created

SendTestMail::getValues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Spatie\MailableTest;
4
5
use Mail;
6
use Exception;
7
use Validator;
8
use Illuminate\Console\Command;
9
10
class SendTestMail extends Command
11
{
12
    protected $signature = 'mail:send-test {mailableClass} {recipient} {--values}';
13
14
    protected $description = 'Send a test email';
15
16
    public function handle()
17
    {
18
        $this->guardAgainstInvalidArguments();
19
20
        $mailable = app(MailableFactory::class)->getInstance(
21
            $this->argument('mailableClass'),
22
            $this->argument('recipient'),
23
            $this->getValues()
24
        );
25
26
        Mail::send($mailable);
27
28
        $this->comment('Mail sent!');
29
    }
30
31
    public function guardAgainstInvalidArguments()
32
    {
33
        $validator = Validator::make(
34
            ['email' => $this->argument('recipient')],
35
            ['email' => 'email']);
36
37
        if (! $validator->passes()) {
38
            throw new Exception("`{$this->argument('recipient')}` is not a valid e-mail address");
39
        }
40
    }
41
42
    protected function getValues(): array
43
    {
44
        return [];
45
    }
46
}
47