OneToAll::postEmail()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 11
cts 11
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 1
crap 2
1
<?php
2
namespace agoalofalife\postman\Modes;
3
4
use agoalofalife\postman\Contract\Mode;
5
6
use Illuminate\Support\Facades\Mail;
7
use agoalofalife\postman\Models\SheduleEmail;
8
use agoalofalife\postman\Models\Status;
9
10
/**
11
 * Class OneToAll
12
 * POST `BCC EMAIL
13
 * @package agoalofalife\postman\Modes
14
 */
15
class OneToAll implements Mode
16
{
17
    /**
18
     * @param SheduleEmail $tasks
19
     */
20
    public function postEmail(SheduleEmail $tasks) : void
21
    {
22 2
        Mail::send('postman::email', ['html' => $tasks->email->text], function($message)  use ($tasks) {
23 2
            $message->subject($tasks->email->theme);
24 2
            $message->from(config('mail.from.address'));
25 2
            $message->to(config('mail.from.address'));
26 2
            $tasks->email->users->each(function ($value) use ($message) {
27 1
                $message->bcc($value->email);
28 2
            });
29 2
         });
30
31
        // if to reached the sender
32 2
        if (empty(Mail::failures())) {
33 1
            $tasks->status_id = Status::done();
34 1
            $tasks->save();
35
        }
36 2
    }
37
38
    /**
39
     *  Get name mode
40
     * @return string
41
     */
42 6
    public function getName(): string
43
    {
44 6
        return trans('postman::mode.one.name');
0 ignored issues
show
Bug Best Practice introduced by
The expression return trans('postman::mode.one.name') could return the type array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
45
    }
46
47
    /**
48
     * Get full description
49
     * @return string
50
     */
51 6
    public function getDescription(): string
52
    {
53 6
        return trans('postman::mode.one.description');
0 ignored issues
show
Bug Best Practice introduced by
The expression return trans('postman::mode.one.description') could return the type array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
54
    }
55
}