Passed
Pull Request — master (#23)
by Nikolay
09:42 queued 03:08
created

CacheCleanerPlugin   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 19
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A beforeDispatch() 0 12 3
1
<?php
2
/**
3
 * Copyright (C) MIKO LLC - All Rights Reserved
4
 * Unauthorized copying of this file, via any medium is strictly prohibited
5
 * Proprietary and confidential
6
 * Written by Nikolay Beketov, 6 2018
7
 *
8
 */
9
10
namespace MikoPBX\AdminCabinet\Plugins;
11
12
use Phalcon\Di\Injectable;
13
14
/**
15
 * CacheCleanerPlugin
16
 *
17
 * Check messages on clean cache queue
18
 */
19
class CacheCleanerPlugin extends Injectable
20
{
21
    /**
22
     * This action is executed before execute any action in the application
23
     *
24
     * @return bool
25
     */
26
    public function beforeDispatch(): bool
27
    {
28
        $queue = $this->getDI()->getShared('beanstalkConnectionCache');
29
30
        $arrayOfClearedModels = $queue->getMessagesFromTube();
31
        foreach ($arrayOfClearedModels as $clearedModel) {
32
            if (class_exists($clearedModel)) {
33
                call_user_func([$clearedModel, 'clearCache'], $clearedModel);
34
            }
35
        }
36
37
        return true;
38
    }
39
}
40