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

ReservationMailer::send()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 31
Code Lines 18

Duplication

Lines 8
Ratio 25.81 %

Code Coverage

Tests 3
CRAP Score 12.192

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 8
loc 31
ccs 3
cts 15
cp 0.2
rs 8.5806
cc 4
eloc 18
nc 2
nop 2
crap 12.192
1
<?php namespace VojtaSvoboda\Reservations\Mailers;
2
3
use App;
4
use Mail;
5
use Request;
6
use VojtaSvoboda\Reservations\Models\Reservation;
7
8
class ReservationMailer extends BaseMailer
9
{
10
    /**
11
     * Send reservation confirmation mail.
12
     *
13
     * @param Reservation $reservation
14
     * @param int $reservationsCount
15
     */
16
    public function send(Reservation $reservation, $reservationsCount = 0)
17
    {
18
        // init
19
        $locale = App::getLocale();
20 6
        $appUrl = App::make('url')->to('/');
21
        $recipients = $this->initRecipients();
22 6
        $recipients['email'] = $reservation->email;
23 6
        $recipients['name'] = trim($reservation->name . ' ' . $reservation->lastname);
24
25
        $template = $this->getTemplateIdent('reservation');
26
27
        $templateParameters = [
28
            'site' => $appUrl,
29
            'reservation' => $reservation,
30
            'locale' => $locale,
31
            'reservationsCount' => $reservationsCount,
32
        ];
33
34
        if (App::environment() === 'testing') {
35
            return;
36
        }
37
38 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...
39
        {
40
            $message->to($recipients['email'], $recipients['name']);
41
42
            if (!empty($recipients['bcc_email']) && !empty($recipients['bcc_name'])) {
43
                $message->bcc($recipients['bcc_email'], $recipients['bcc_name']);
44
            }
45
        });
46
    }
47
}
48