RepositoryEventListener::entityUpdating()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Repository\Listeners;
6
7
use Illuminate\Contracts\Events\Dispatcher;
8
9
class RepositoryEventListener
10
{
11
    /**
12
     * Register the listeners for the subscriber.
13
     *
14
     * @param \Illuminate\Contracts\Events\Dispatcher $dispatcher
15
     */
16
    public function subscribe(Dispatcher $dispatcher)
17
    {
18
        $dispatcher->listen('*.entity.creating', self::class.'@entityCreating');
19
        $dispatcher->listen('*.entity.created', self::class.'@entityCreated');
20
        $dispatcher->listen('*.entity.updating', self::class.'@entityUpdating');
21
        $dispatcher->listen('*.entity.updated', self::class.'@entityUpdated');
22
        $dispatcher->listen('*.entity.deleting', self::class.'@entityDeleting');
23
        $dispatcher->listen('*.entity.deleted', self::class.'@entityDeleted');
24
    }
25
26
    /**
27
     * Listen to entities being created.
28
     *
29
     * @param string $eventName
30
     * @param array  $data
31
     *
32
     * @return void
33
     */
34
    public function entityCreating($eventName, $data): void
0 ignored issues
show
Unused Code introduced by
The parameter $eventName is not used and could be removed.

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

Loading history...
Unused Code introduced by
The parameter $data is not used and could be removed.

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

Loading history...
35
    {
36
        //
37
    }
38
39
    /**
40
     * Listen to entities created.
41
     *
42
     * @param string $eventName
43
     * @param array  $data
44
     *
45
     * @return void
46
     */
47
    public function entityCreated($eventName, $data): void
0 ignored issues
show
Unused Code introduced by
The parameter $eventName is not used and could be removed.

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

Loading history...
48
    {
49
        $clearOn = $data[0]->getContainer('config')->get('rinvex.repository.cache.clear_on');
50
51
        if ($data[0]->isCacheClearEnabled() && in_array('create', $clearOn)) {
52
            $data[0]->forgetCache();
53
        }
54
    }
55
56
    /**
57
     * Listen to entities being updated.
58
     *
59
     * @param string $eventName
60
     * @param array  $data
61
     *
62
     * @return void
63
     */
64
    public function entityUpdating($eventName, $data): void
0 ignored issues
show
Unused Code introduced by
The parameter $eventName is not used and could be removed.

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

Loading history...
Unused Code introduced by
The parameter $data is not used and could be removed.

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

Loading history...
65
    {
66
        //
67
    }
68
69
    /**
70
     * Listen to entities updated.
71
     *
72
     * @param string $eventName
73
     * @param array  $data
74
     *
75
     * @return void
76
     */
77
    public function entityUpdated($eventName, $data): void
0 ignored issues
show
Unused Code introduced by
The parameter $eventName is not used and could be removed.

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

Loading history...
78
    {
79
        $clearOn = $data[0]->getContainer('config')->get('rinvex.repository.cache.clear_on');
80
81
        if ($data[0]->isCacheClearEnabled() && in_array('update', $clearOn)) {
82
            $data[0]->forgetCache();
83
        }
84
    }
85
86
    /**
87
     * Listen to entities being deleted.
88
     *
89
     * @param string $eventName
90
     * @param array  $data
91
     *
92
     * @return void
93
     */
94
    public function entityDeleting($eventName, $data): void
0 ignored issues
show
Unused Code introduced by
The parameter $eventName is not used and could be removed.

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

Loading history...
Unused Code introduced by
The parameter $data is not used and could be removed.

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

Loading history...
95
    {
96
        //
97
    }
98
99
    /**
100
     * Listen to entities deleted.
101
     *
102
     * @param string $eventName
103
     * @param array  $data
104
     *
105
     * @return void
106
     */
107
    public function entityDeleted($eventName, $data): void
0 ignored issues
show
Unused Code introduced by
The parameter $eventName is not used and could be removed.

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

Loading history...
108
    {
109
        $clearOn = $data[0]->getContainer('config')->get('rinvex.repository.cache.clear_on');
110
111
        if ($data[0]->isCacheClearEnabled() && in_array('delete', $clearOn)) {
112
            $data[0]->forgetCache();
113
        }
114
    }
115
}
116