Completed
Push — master ( f774d7...cef3a1 )
by Alessandro
116:58 queued 114:39
created

MailHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Alessandro
5
 * Date: 03/12/2015
6
 * Time: 17:25
7
 */
8
9
namespace Padosoft\LaravelComposerSecurity;
10
11
use Config;
12
use Validator;
13
use Illuminate\Console\Command;
14
use Illuminate\Mail\Message;
15
use Mail;
16
17
class MailHelper
18
{
19
20
    protected $command;
21
22
    /**
23
     *
24
     */
25
    public function setUp()
26
    {
27
        parent::setUp();
28
    }
29
30
    /**
31
     * MailHelper constructor.
32
     * @param Command $objcommand
33
     */
34 18
    public function __construct(Command $objcommand)
35
    {
36 18
        $this->command = $objcommand;
37 18
    }
38
39
    /**
40
     * @param $tuttoOk
41
     * @param $mail
42
     * @param $vul
43
     */
44 18
    public function sendEmail($tuttoOk, $mail, $vul)
45
    {
46 18
        $soggetto=Config::get('composer-security-check.mailSubjectSuccess');
47
48 18
        if (!$tuttoOk) {
49 8
            $soggetto=Config::get('composer-security-check.mailSubjetcAlarm');
50
        }
51
52 18
        $validator = Validator::make(['email' => $mail], [
53 18
            'email' => 'required|email',
54
        ]);
55 18
        if ($validator->fails()) {
56
            $this->command->error('No valid email passed: '.$mail.'. Mail will not be sent.');
57
            return;
58
        }
59 18
        $this->command->line('Send email to <info>'.$mail.'</info>');
60
61 18
        Mail::send(
62 18
            Config::get('composer-security-check.mailViewName'),
63 18
            ['vul' => $vul],
64 18
            function (Message $message) use ($mail, $soggetto) {
65 18
                $message->from(
66 18
                    Config::get('composer-security-check.mailFrom'),
67 18
                    Config::get('composer-security-check.mailFromName')
68
                );
69 18
                $message->to($mail, $mail);
70 18
                $message->subject($soggetto);
71 18
            }
72
        );
73
74
75 18
        $this->command->line('email sent.');
76
77 18
    }
78
}
79