Passed
Push — master ( 62a61a...c49d39 )
by Chubarov
05:18
created

Each::postEmail()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
ccs 7
cts 7
cp 1
cc 2
eloc 7
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 View Code Duplication
class Each implements Mode
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    /**
12
     * @param SheduleEmail $tasks
13
     * @return mixed|void
14
     */
15
    public function postEmail(SheduleEmail $tasks)
16
    {
17 1
        Mail::raw($tasks->email->text, function ($message) use ($tasks) {
18 1
        $message->subject($tasks->email->theme);
19 1
        $message->from(config('mail.from.address'));
20
        $message->to($tasks->email->users->map(function($value){ return $value->email;})->toArray());
21 1
    });
22
23
        // if to reached the sender
24 1
        if (empty(Mail::failures())) {
25 1
            $tasks->status_id = Status::done();
26 1
            $tasks->save();
27
        }
28 1
    }
29
30
    /**
31
     *  Get name mode
32
     * @return string
33
     */
34 6
    public function getName(): string
35
    {
36 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 Illuminate\Contracts\Tra...n\Translator|null|array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
37
    }
38
39
    /**
40
     * Get full description
41
     * @return string
42
     */
43 6
    public function getDescription(): string
44
    {
45 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 Illuminate\Contracts\Tra...n\Translator|null|array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
46
    }
47
}