Passed
Push — master ( 7cbfe3...bc244d )
by Krisztián
05:18
created

CacheEventListener   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A onGet() 0 11 1
A onDelete() 0 11 1
A __construct() 0 3 1
A onSet() 0 11 1
1
<?php
2
3
/*
4
 * All rights reserved © 2018 Legow Hosting Kft.
5
 */
6
7
namespace PhpCache\Example\EventListener;
8
9
use DateTimeImmutable;
10
use DateTimeZone;
11
use PhpCache\CacheEventListener\CacheEventListenerInterface;
12
use PhpCache\Example\Logger\LogEntry;
13
14
/**
15
 * Description of CacheEventListener.
16
 *
17
 * @author kdudas
18
 */
19
class CacheEventListener implements CacheEventListenerInterface
20
{
21
    private $logger;
22
23
    public function __construct($logger)
24
    {
25
        $this->logger = $logger;
26
    }
27
28
    public function onDelete($key, $entry)
29
    {
30
        $logEntry = new LogEntry(
31
            new DateTimeImmutable(date('Y-m-d H:i:s'), new DateTimeZone('UTC')),
32
            LogEntry::SEVERITY_INFO,
33
            'Cache Entry with key '.$key.' deleted'
34
        );
35
36
        $this->logger->log($logEntry);
37
38
        return $entry;
39
    }
40
41
    public function onGet($key, $entry)
42
    {
43
        $logEntry = new LogEntry(
44
            new DateTimeImmutable(date('Y-m-d H:i:s'), new DateTimeZone('UTC')),
45
            LogEntry::SEVERITY_INFO,
46
            'Cache Entry with key '.$key.' requested'
47
        );
48
49
        $this->logger->log($logEntry);
50
51
        return $entry;
52
    }
53
54
    public function onSet($key, $entry)
55
    {
56
        $logEntry = new LogEntry(
57
            new DateTimeImmutable(date('Y-m-d H:i:s'), new DateTimeZone('UTC')),
58
            LogEntry::SEVERITY_INFO,
59
            'Cache Entry with key '.$key.' was set into cache pool'
60
        );
61
62
        $this->logger->log($logEntry);
63
64
        return $entry;
65
    }
66
}
67