ErrorListener   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 5
Bugs 2 Features 0
Metric Value
wmc 3
c 5
b 2
f 0
lcom 0
cbo 3
dl 0
loc 39
ccs 0
cts 16
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A sendEmail() 0 7 1
A __construct() 0 4 1
A handle() 0 8 1
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