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