CachedBehavior::afterDelete()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
/**
3
 * CakeCMS Core
4
 *
5
 * This file is part of the of the simple cms based on CakePHP 3.
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @package     Core
10
 * @license     MIT
11
 * @copyright   MIT License http://www.opensource.org/licenses/mit-license.php
12
 * @link        https://github.com/CakeCMS/Core".
13
 * @author      Sergey Kalistratov <[email protected]>
14
 */
15
16
namespace Core\ORM\Behavior;
17
18
use Cake\ORM\Entity;
19
use Cake\Cache\Cache;
20
use Cake\Event\Event;
21
use Cake\ORM\Behavior;
22
use Cake\Utility\Hash;
23
24
/**
25
 * Class CachedBehavior
26
 *
27
 * @package Core\ORM\Behavior
28
 */
29
class CachedBehavior extends Behavior
30
{
31
32
    /**
33
     * Default config.
34
     *
35
     * @var array
36
     */
37
    protected $_defaultConfig = [
38
        'config' => 'default',
39
        'prefix' => null,
40
        'groups' => [],
41
    ];
42
43
    /**
44
     * Initialize hook.
45
     *
46
     * @param array $config The config for this behavior.
47
     * @return void
48
     */
49
    public function initialize(array $config)
50
    {
51
        $config = Hash::merge($this->_defaultConfig, $config);
52
        $this->setConfig($config);
53
    }
54
55
    /**
56
     * Clear cache group after save.
57
     *
58
     * @param Event $event
59
     * @param Entity $entity
60
     * @param \ArrayObject $options
61
     * @SuppressWarnings("unused")
62
     */
63
    public function afterSave(Event $event, Entity $entity, \ArrayObject $options)
0 ignored issues
show
Unused Code introduced by
The parameter $event 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 $entity 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 $options 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...
64
    {
65
        $this->_clearCacheGroup();
66
    }
67
68
    /**
69
     * Clear cache group after delete.
70
     *
71
     * @param Event $event
72
     * @param Entity $entity
73
     * @param \ArrayObject $options
74
     * @SuppressWarnings("unused")
75
     */
76
    public function afterDelete(Event $event, Entity $entity, \ArrayObject $options)
0 ignored issues
show
Unused Code introduced by
The parameter $event 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 $entity 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 $options 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...
77
    {
78
        $this->_clearCacheGroup();
79
    }
80
81
    /**
82
     * Clear cache group.
83
     *
84
     * @return void
85
     */
86
    protected function _clearCacheGroup()
87
    {
88
        $cacheGroups = (array) $this->getConfig('groups');
89
        foreach ($cacheGroups as $group) {
90
            Cache::clearGroup($group, $this->getConfig('config'));
91
        }
92
    }
93
}
94