TournamentObserver::updating()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.2
c 0
b 0
f 0
cc 4
eloc 7
nc 4
nop 1
1
<?php
2
3
namespace App\Observers;
4
5
use App\Events\Tournament\TournamentWasReset;
6
use App\Events\Tournament\TournamentWasStarted;
7
use App\Tournament;
8
9
/**
10
 * Class TournamentObserver
11
 * @package App\Observers
12
 */
13
class TournamentObserver
14
{
15
    /**
16
     * @param Tournament $model
17
     */
18
    public function updating(Tournament $model)
19
    {
20
        $dirtyStatus = array_get($model->getDirty(), 'status');
21
22
        if (Tournament::STATUS_STARTED === $dirtyStatus
23
            && 1 > $model->matches()->getResults()->count()
24
        ) {
25
            event(new TournamentWasStarted($model));
26
        }
27
28
        if (Tournament::STATUS_DRAFT === $dirtyStatus) {
29
            event(new TournamentWasReset($model));
30
        }
31
    }
32
}
33