ErrorListener::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 8
ccs 0
cts 6
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 2
1
<?php
2
3
namespace plunner\Listeners\Optimise;
4
5
use plunner\Events\Optimise\ErrorEvent;
6
7
class ErrorListener
8
{
9
    /**
10
     * Create the event listener.
11
     *
12
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
13
     */
14
    public function __construct()
15
    {
16
        //
17
    }
18
19
    /**
20
     * Handle the event.
21
     *
22
     * @param  ErrorEvent $event
23
     * @return void
24
     */
25
    public function handle(ErrorEvent $event)
26
    {
27
        //
28
        \Log::error('problems during optimise (company id = ' . $event->getCompany()->id . '): ' . $event->getError());
29
        $company = $event->getCompany();
30
        //$company = $event->getCompany()->fresh();
31
        self::sendEmail($company->email, $event->getError());
32
    }
33
34
    /**
35
     * @param string $email
36
     * @param string $error
37
     */
38
    static private function sendEmail($email, $error)
39
    {
40
        \Mail::queue('emails.optimise.error', ['error' => $error], function ($message) use ($email) {
41
            $message->from(config('mail.from.address'), config('mail.from.name'));
42
            $message->to($email)->subject('Problems during optimisation');
43
        });
44
    }
45
}
46