Completed
Push — dev ( a25222...cc464e )
by Gray
05:55
created

ApplicationStatusChanged   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
eloc 14
dl 0
loc 41
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A handle() 0 23 4
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace App\Listeners;
4
5
use App\Events\ApplicationSaved;
6
use Illuminate\Queue\InteractsWithQueue;
7
use Illuminate\Contracts\Queue\ShouldQueue;
8
use Illuminate\Support\Facades\Log;
9
use Illuminate\Support\Facades\Auth;
10
11
class ApplicationStatusChanged
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class ApplicationStatusChanged
Loading history...
12
{
13
    /**
14
     * Create the event listener.
15
     *
16
     * @return void
17
     */
18
    public function __construct()
19
    {
20
        //
21
    }
22
23
    /**
24
     * Handle the event.
25
     *
26
     * @param  ApplicationSaved  $event
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
27
     * @return void
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
28
     */
29
    public function handle(ApplicationSaved $event)
30
    {
31
        $application = $event->application;
32
33
        if (Auth::check()) {
34
            $user = Auth::user();
35
            $userText = "{id=".$user->id.", email=".$user->email."}";
0 ignored issues
show
Bug introduced by
Accessing email on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
36
        } else {
37
            $userText = "{null}";
38
        }
39
40
        //Log when application is first created
41
        if($application->wasRecentlyCreated) {
0 ignored issues
show
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
42
            $applicationText = "{id=".$application->id.", status=".$application->application_status->name."}";
43
44
            Log::notice("Application created: application ".$applicationText." has been created by user ".$userText);
45
        }
46
        //Log if application status has been changed
47
        else if ($application->application_status_id != $application->getOriginal('application_status_id')) {
0 ignored issues
show
Coding Style introduced by
Expected "} else if (...) \n"; found "\n //Log if application status has been changed\n else if (...) {\n"
Loading history...
48
            $applicationText = "{id=".$application->id."}";
49
            $statusText = "{".$application->application_status->name."}";
50
51
            Log::notice("Application status changed: application ".$applicationText." has been changed to ".$statusText." by user ".$userText);
52
        }
53
    }
54
}
55