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

OneToAll   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

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

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
6
use Illuminate\Support\Facades\Mail;
7
use agoalofalife\postman\Models\SheduleEmail;
8
9
/**
10
 * Class OneToAll
11
 * POST `BCC EMAIL
12
 * @package agoalofalife\postman\Modes
13
 */
14 View Code Duplication
class OneToAll 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...
15
{
16
    /**
17
     * @param SheduleEmail $tasks
18
     */
19
    public function postEmail(SheduleEmail $tasks) : void
20
    {
21 1
         Mail::raw($tasks->email->text, function ($message) use ($tasks) {
22 1
            $message->subject($tasks->email->theme);
23 1
            $message->from(config('mail.from.address'));
24 1
            $message->to(config('mail.from.address'));
25
26 1
            $tasks->email->users->each(function ($value) use ($message) {
27 1
                $message->bcc($value->email);
28 1
            });
29 1
         });
30
31
        // if to reached the sender
32 1
        if (empty(Mail::failures())) {
33 1
            $tasks->status_action = 1;
34 1
            $tasks->save();
35
        }
36 1
    }
37
38
    /**
39
     *  Get name mode
40
     * @return string
41
     */
42 2
    public function getName(): string
43
    {
44 2
        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 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
47
    /**
48
     * Get full description
49
     * @return string
50
     */
51 2
    public function getDescription(): string
52
    {
53 2
        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 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...
54
    }
55
}