Passed
Branch master (328f34)
by Chubarov
04:39
created

Each   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Test Coverage

Coverage 33.33%

Importance

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

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 Illuminate\Support\Facades\Mail;
7
8 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...
9
{
10
    /**
11
     * @param SheduleEmail $tasks
12
     * @return mixed|void
13
     */
14
    public function postEmail(SheduleEmail $tasks)
15
    {
16
        Mail::raw($tasks->email->text, function ($message) use ($tasks) {
17
        $message->subject($tasks->email->theme);
18
        $message->from(config('mail.from.address'));
19
        $message->to($tasks->email->users->map(function($value){ return $value->email;})->toArray());
20
    });
21
22
        // if to reached the sender
23
        if (empty(Mail::failures())) {
24
            $tasks->status_action = 1;
25
            $tasks->save();
26
        }
27
    }
28
29
    /**
30
     *  Get name mode
31
     * @return string
32
     */
33 2
    public function getName(): string
34
    {
35 2
        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...
36
    }
37
38
    /**
39
     * Get full description
40
     * @return string
41
     */
42 2
    public function getDescription(): string
43
    {
44 2
        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...
45
    }
46
}