PageInvalidator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 9 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Website\Events\Listeners;
6
7
use AbterPhp\Framework\Events\EntityChange;
8
use AbterPhp\Framework\Template\CacheManager;
9
use AbterPhp\Website\Domain\Entities\Block;
10
use AbterPhp\Website\Domain\Entities\Page;
11
use AbterPhp\Website\Domain\Entities\PageLayout;
12
13
class PageInvalidator
14
{
15
    /** @var CacheManager */
16
    protected $cacheManager;
17
18
    /**
19
     * AuthInvalidator constructor.
20
     *
21
     * @param CacheManager $cacheManager
22
     */
23
    public function __construct(CacheManager $cacheManager)
24
    {
25
        $this->cacheManager = $cacheManager;
26
    }
27
28
    /**
29
     * @param EntityChange $event
30
     */
31
    public function handle(EntityChange $event)
32
    {
33
        $entity = $event->getEntity();
34
        if ($entity instanceof Page) {
35
            $this->cacheManager->flush();
36
        } elseif ($entity instanceof PageLayout) {
37
            $this->cacheManager->flush();
38
        } elseif ($entity instanceof Block) {
39
            $this->cacheManager->flush();
40
        }
41
    }
42
}
43