Completed
Push — master ( 4e9098...833ca6 )
by Alessandro
58:43 queued 55:12
created

MailHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 82.14%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
c 1
b 1
f 0
lcom 1
cbo 1
dl 0
loc 62
ccs 23
cts 28
cp 0.8214
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A __construct() 0 4 1
B sendEmail() 0 34 3
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
        }
51
52 6
        $validator = Validator::make(['email' => $mail], [
53 6
            'email' => 'required|email',
54
        ]);
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
                );
69 6
                $message->to($mail, $mail);
70 6
                $message->subject($soggetto);
71 6
            }
72
        );
73
74
75 6
        $this->command->line('email sent.');
76
77 6
    }
78
}
79