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

Each   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
dl 37
loc 37
rs 10
c 0
b 0
f 0
ccs 12
cts 12
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A postEmail() 12 12 2
A getDescription() 3 3 1
A getName() 3 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}