Completed
Push — master ( 3afd02...a4590b )
by Vojta
04:54
created

ReservationAdminMailer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 17.39 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 16.66%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 1
dl 8
loc 46
ccs 3
cts 18
cp 0.1666
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B send() 8 37 6

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 namespace VojtaSvoboda\Reservations\Mailers;
2
3
use App;
4
use Mail;
5
use Request;
6
use VojtaSvoboda\Reservations\Models\Reservation;
7
use VojtaSvoboda\Reservations\Models\Settings;
8
9
class ReservationAdminMailer extends BaseMailer
10
{
11
    /**
12
     * Send reservation confirmation mail.
13
     *
14
     * @param Reservation $reservation
15
     * @param int $reservationsCount
16
     */
17
    public function send(Reservation $reservation, $reservationsCount = 0)
18
    {
19
        // init
20
        $locale = App::getLocale();
21 6
        $appUrl = App::make('url')->to('/');
22
        $enabled = Settings::get('admin_confirmation_enable');
23 6
        $recipients = $this->initRecipients();
24 6
        $recipients['email'] = Settings::get('admin_confirmation_email');
25
        $recipients['name'] = Settings::get('admin_confirmation_name');
26
27
        // skip if disabled or empty email
28
        if (!$enabled || empty($recipients['email'])) {
29
            return;
30
        }
31
32
        $template = $this->getTemplateIdent('reservation-admin');
33
34
        $templateParameters = [
35
            'site' => $appUrl,
36
            'reservation' => $reservation,
37
            'locale' => $locale,
38
            'reservationsCount' => $reservationsCount,
39
        ];
40
41
        if (App::environment() === 'testing') {
42
            return;
43
        }
44
45 View Code Duplication
        Mail::send($template, $templateParameters, function($message) use ($recipients)
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
46
        {
47
            $message->to($recipients['email'], $recipients['name']);
48
49
            if (!empty($recipients['bcc_email']) && !empty($recipients['bcc_name'])) {
50
                $message->bcc($recipients['bcc_email'], $recipients['bcc_name']);
51
            }
52
        });
53
    }
54
}
55