MailHelper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 62
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A __construct() 0 4 1
A sendEmail() 0 34 3
1
<?php
2
3
namespace Padosoft\Laravel\Google\StructuredDataTestingTool;
4
5
use Config;
6
use Validator;
7
use Illuminate\Console\Command;
8
use Mail;
9
10
class MailHelper
11
{
12
13
    protected $command;
14
15
    /**
16
     *
17
     */
18
    public function setUp()
19
    {
20
        parent::setUp();
21
    }
22
23
    /**
24
     * MailHelper constructor.
25
     * @param Command $objcommand
26
     */
27
    public function __construct(Command $objcommand)
28
    {
29
        $this->command = $objcommand;
30
    }
31
32
    /**
33
     * @param $tuttoOk
34
     * @param $mail
35
     * @param $vul
36
     */
37
    public function sendEmail($tuttoOk, $mail, $vul)
38
    {
39
        $soggetto = Config::get('laravel-google-structured-data-testing-tool.mailSubjectSuccess');
40
41
        if (!$tuttoOk) {
42
            $soggetto = Config::get('laravel-google-structured-data-testing-tool.mailSubjetcAlarm');
43
        }
44
45
        $validator = Validator::make(['email' => $mail], [
46
            'email' => 'required|email',
47
        ]);
48
        if ($validator->fails()) {
49
            $this->command->error('No valid email passed: ' . $mail . '. Mail will not be sent.');
50
            return;
51
        }
52
        $this->command->line('Send email to <info>' . $mail . '</info>');
53
54
        Mail::send(
55
            Config::get('laravel-google-structured-data-testing-tool.mailViewName'),
56
            ['vul' => $vul],
57
            function (\Illuminate\Mail\Message $message) use ($mail, $soggetto) {
58
                $message->from(
59
                    Config::get('laravel-google-structured-data-testing-tool.mailFrom'),
60
                    Config::get('laravel-google-structured-data-testing-tool.mailFromName')
61
                );
62
                $message->to($mail, $mail);
63
                $message->subject($soggetto);
64
            }
65
        );
66
67
68
        $this->command->line('email sent.');
69
70
    }
71
}
72