MailHelper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 84.38%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 62
ccs 27
cts 32
cp 0.8438
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
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 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 22
    public function __construct(Command $objcommand)
34
    {
35 22
        $this->command = $objcommand;
36 22
    }
37
38
    /**
39
     * @param $tuttoOk
40
     * @param $mail
41
     * @param $vul
42
     */
43 22
    public function sendEmail($tuttoOk, $mail, $vul)
44
    {
45 22
        $soggetto=Config::get('composer-security-check.mailSubjectSuccess');
46
47 22
        if (!$tuttoOk) {
48 10
            $soggetto=Config::get('composer-security-check.mailSubjetcAlarm');
49 10
        }
50
51 22
        $validator = Validator::make(['email' => $mail], [
52 22
            'email' => 'required|email',
53 22
        ]);
54 22
        if ($validator->fails()) {
55
            $this->command->error('No valid email passed: '.$mail.'. Mail will not be sent.');
56
            return;
57
        }
58 22
        $this->command->line('Send email to <info>'.$mail.'</info>');
59
60 22
        Mail::send(
61 22
            Config::get('composer-security-check.mailViewName'),
62 22
            ['vul' => $vul],
63 22
            function ($message) use ($mail, $soggetto) {
64 22
                $message->from(
65 22
                    Config::get('composer-security-check.mailFrom'),
66 22
                    Config::get('composer-security-check.mailFromName')
67 22
                );
68 22
                $message->to($mail, $mail);
69 22
                $message->subject($soggetto);
70 22
            }
71 22
        );
72
73
74 22
        $this->command->line('email sent.');
75
76 22
    }
77
}
78