Issues (35)

src/AuditableObserver.php (1 issue)

1
<?php
2
3
namespace OwenIt\Auditing;
4
5
use OwenIt\Auditing\Contracts\Auditable;
6
use OwenIt\Auditing\Facades\Auditor;
7
8
class AuditableObserver
9
{
10
    /**
11
     * Is the model being restored?
12
     *
13
     * @var bool
14
     */
15
    public static $restoring = false;
16
17
    /**
18
     * Handle the retrieved event.
19
     *
20
     * @param \OwenIt\Auditing\Contracts\Auditable $model
21
     *
22
     * @return void
23
     */
24 20
    public function retrieved(Auditable $model)
25
    {
26 20
        Auditor::execute($model->setAuditEvent('retrieved'));
27 20
    }
28
29
    /**
30
     * Handle the created event.
31
     *
32
     * @param \OwenIt\Auditing\Contracts\Auditable $model
33
     *
34
     * @return void
35
     */
36 50
    public function created(Auditable $model)
37
    {
38 50
        Auditor::execute($model->setAuditEvent('created'));
39 48
    }
40
41
    /**
42
     * Handle the updated event.
43
     *
44
     * @param \OwenIt\Auditing\Contracts\Auditable $model
45
     *
46
     * @return void
47
     */
48 6
    public function updated(Auditable $model)
49
    {
50
        // Ignore the updated event when restoring
51 6
        if (!static::$restoring) {
52 5
            Auditor::execute($model->setAuditEvent('updated'));
53
        }
54 6
    }
55
56
    /**
57
     * Handle the deleted event.
58
     *
59
     * @param \OwenIt\Auditing\Contracts\Auditable $model
60
     *
61
     * @return void
62
     */
63 3
    public function deleted(Auditable $model)
64
    {
65 3
        Auditor::execute($model->setAuditEvent('deleted'));
66 3
    }
67
68
    /**
69
     * Handle the restoring event.
70
     *
71
     * @param \OwenIt\Auditing\Contracts\Auditable $model
72
     *
73
     * @return void
74
     */
75 2
    public function restoring(Auditable $model)
0 ignored issues
show
The parameter $model is not used and could be removed. ( Ignorable by Annotation )

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

75
    public function restoring(/** @scrutinizer ignore-unused */ Auditable $model)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
76
    {
77
        // When restoring a model, an updated event is also fired.
78
        // By keeping track of the main event that took place,
79
        // we avoid creating a second audit with wrong values
80 2
        static::$restoring = true;
81 2
    }
82
83
    /**
84
     * Handle the restored event.
85
     *
86
     * @param \OwenIt\Auditing\Contracts\Auditable $model
87
     *
88
     * @return void
89
     */
90 2
    public function restored(Auditable $model)
91
    {
92 2
        Auditor::execute($model->setAuditEvent('restored'));
93
94
        // Once the model is restored, we need to put everything back
95
        // as before, in case a legitimate update event is fired
96 2
        static::$restoring = false;
97 2
    }
98
}
99