TournamentObserver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A updating() 0 14 4
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