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

ReservationAdminMailer::getReservationsCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
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