Each::postEmail()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 1
crap 2
1
<?php
2
namespace agoalofalife\postman\Modes;
3
4
use agoalofalife\postman\Contract\Mode;
5
use agoalofalife\postman\Models\SheduleEmail;
6
use agoalofalife\postman\Models\Status;
7
use Illuminate\Support\Facades\Mail;
8
9
class Each implements Mode
10
{
11
    /**
12
     * @link https://github.com/laravel/framework/issues/10235
13
     * @param SheduleEmail $tasks
14
     * @return mixed|void
15
     */
16 1
    public function postEmail(SheduleEmail $tasks)
17
    {
18 1
        $template = config('postman.templates.'.get_class($this));
19 1
        Mail::send($template['name_template'], [$template['variable'] => $tasks->email->text], function($message)  use ($tasks) {
20 1
            $message->subject($tasks->email->theme);
21 1
            $message->from(config('mail.from.address'));
22
            $message->to($tasks->email->users->map(function($value){ return $value->email;})->toArray());
23 1
        });
24
25
        // if to reached the sender
26 1
        if (empty(Mail::failures())) {
27 1
            $tasks->status_id = Status::done();
28 1
            $tasks->save();
29
        }
30 1
    }
31
32
    /**
33
     *  Get name mode
34
     * @return string
35
     */
36 6
    public function getName(): string
37
    {
38 6
        return trans('postman::mode.two.name');
0 ignored issues
show
Bug Best Practice introduced by
The expression return trans('postman::mode.two.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...
39
    }
40
41
    /**
42
     * Get full description
43
     * @return string
44
     */
45 6
    public function getDescription(): string
46
    {
47 6
        return trans('postman::mode.two.name');
0 ignored issues
show
Bug Best Practice introduced by
The expression return trans('postman::mode.two.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...
48
    }
49
}