Completed
Push — master ( df288a...fc83fd )
by Joseph
9s
created

Cache   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 29
ccs 14
cts 14
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 10 2
A set() 0 8 1
1
<?php
2
3
namespace Jclyons52\PagePreview\Cache;
4
5
use Jclyons52\PagePreview\Preview;
6
use Psr\Cache\CacheItemPoolInterface;
7
8
class Cache
9
{
10
    private $pool;
11
12 9
    public function __construct(CacheItemPoolInterface $pool)
13
    {
14 9
        $this->pool = $pool;
15 9
    }
16
17 9
    public function get($key)
18
    {
19 9
        $item = $this->pool->getItem(md5($key));
20
21 9
        $preview = unserialize($item->get());
22
23 9
        if ($preview instanceof Preview) {
24 6
            return $preview;
25
        }
26 3
    }
27
28 6
    public function set(Preview $preview)
29
    {
30 6
        $item = $this->pool->getItem(md5($preview->url));
31
32 6
        $item->set(serialize($preview));
33
34 6
        $this->pool->save($item);
35 6
    }
36
}
37