LogObserver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 21
dl 0
loc 40
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A observeDelete() 0 9 1
A observeUpdate() 0 7 1
A getEntity() 0 3 1
A observeCreate() 0 9 1
1
<?php
2
namespace backend\observers;
3
4
use yii\base\ModelEvent;
5
use yii\db\AfterSaveEvent;
6
use backend\models\Log;
7
use yii\db\ActiveRecord;
8
9
class LogObserver
10
{
11
    public function observeCreate(AfterSaveEvent $event)
12
    {
13
        Log::find()
14
            ->createLogEntity(
15
                self::getEntity($event),
0 ignored issues
show
Bug Best Practice introduced by
The method backend\observers\LogObserver::getEntity() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

15
                self::/** @scrutinizer ignore-call */ 
16
                      getEntity($event),
Loading history...
16
                Log::ACTION_CREATE,
17
                false,
18
                true
19
            )->save();
20
    }
21
22
    public function observeUpdate(ModelEvent $event)
23
    {
24
        Log::find()
25
            ->createLogEntity(
26
                self::getEntity($event),
0 ignored issues
show
Bug Best Practice introduced by
The method backend\observers\LogObserver::getEntity() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
                self::/** @scrutinizer ignore-call */ 
27
                      getEntity($event),
Loading history...
27
                Log::ACTION_UPDATE
28
            )->save();
29
    }
30
31
    public function observeDelete(ModelEvent $event)
32
    {
33
        Log::find()
34
            ->createLogEntity(
35
                self::getEntity($event),
0 ignored issues
show
Bug Best Practice introduced by
The method backend\observers\LogObserver::getEntity() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
                self::/** @scrutinizer ignore-call */ 
36
                      getEntity($event),
Loading history...
36
                Log::ACTION_DELETE,
37
                true,
38
                false
39
            )->save();
40
    }
41
42
    /**
43
     * @param $event
44
     * @return ActiveRecord
45
     */
46
    protected function getEntity($event)
47
    {
48
        return $event->sender;
49
    }
50
}
51