Completed
Push — master ( 8b982b...991834 )
by Alessandro
05:30
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 1
Bugs 1 Features 0
Metric Value
c 1
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 6
    public function __construct(Command $objcommand)
35
    {
36 6
        $this->command = $objcommand;
37 6
    }
38
39
    /**
40
     * @param $tuttoOk
41
     * @param $mail
42
     * @param $vul
43
     */
44 6
    public function sendEmail($tuttoOk, $mail, $vul)
45
    {
46 6
        $soggetto=Config::get('composer-security-check.mailSubjectSuccess');
47
48 6
        if (!$tuttoOk) {
49 4
            $soggetto=Config::get('composer-security-check.mailSubjetcAlarm');
50 4
        }
51
52 6
        $validator = Validator::make(['email' => $mail], [
53 6
            'email' => 'required|email',
54 6
        ]);
55 6
        if ($validator->fails()) {
56
            $this->command->error('No valid email passed: '.$mail.'. Mail will not be sent.');
57
            return;
58
        }
59 6
        $this->command->line('Send email to <info>'.$mail.'</info>');
60
61 6
        Mail::send(
62 6
            Config::get('composer-security-check.mailViewName'),
63 6
            ['vul' => $vul],
64 6
            function (Message $message) use ($mail, $soggetto) {
65 6
                $message->from(
66 6
                    Config::get('composer-security-check.mailFrom'),
67 6
                    Config::get('composer-security-check.mailFromName')
68 6
                );
69 6
                $message->to($mail, $mail);
70 6
                $message->subject($soggetto);
71 6
            }
72 6
        );
73
74
75 6
        $this->command->line('email sent.');
76
77 6
    }
78
}
79