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

SendTestMail   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 37
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 14 1
A guardAgainstInvalidArguments() 0 10 2
A getValues() 0 4 1
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