Completed
Push — master ( dc6f94...d4342e )
by Alessandro
06:08
created

MailHelper::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

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