TimeLogSaved::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 4
nop 1
dl 0
loc 11
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace App\Events;
4
5
use App\TimeLog;
6
use Illuminate\Queue\SerializesModels;
7
use Illuminate\Foundation\Events\Dispatchable;
8
use App\Notifications\ProjectIsAtFiftyPercentTime;
9
use App\Notifications\ProjectIsAtEightyPercentTime;
10
use App\Notifications\ProjectIsAtOneHundredPercentTime;
11
12
class TimeLogSaved
13
{
14
    use Dispatchable, SerializesModels;
0 ignored issues
show
introduced by
The trait Illuminate\Queue\SerializesModels requires some properties which are not provided by App\Events\TimeLogSaved: $id, $class, $connection, $relations
Loading history...
15
16
    public $timelog;
17
18
    /**
19
     * Create a new event instance.
20
     *
21
     * @return void
22
     */
23
    public function __construct(TimeLog $timelog)
24
    {
25
        $project = $timelog->project;
26
27
        // @todo only notify each user once, save spamming
28
        if ($project->percentage_taken >= 100) {
29
            $project->user->notify(new ProjectIsAtOneHundredPercentTime($project->user, $project));
30
        } elseif ($project->percentage_taken >= 80) {
31
            $project->user->notify(new ProjectIsAtEightyPercentTime($project->user, $project));
32
        } elseif ($project->percentage_taken >= 50) {
33
            $project->user->notify(new ProjectIsAtFiftyPercentTime($project->user, $project));
34
        }
35
    }
36
}
37