Completed
Push — master ( de1e0b...7a42c8 )
by Patryk
03:54 queued 53s
created

SymfonyCacheBridge::save()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 3
crap 2
1
<?php
2
3
namespace KaLLoSz\Twig\Extension\Cache;
4
5
use Symfony\Component\Cache\Adapter\AdapterInterface;
6
7
/**
8
 * Class SymfonyCacheBridge
9
 * @package KaLLoSz\Twig\Extension\Cache
10
 *
11
 * @author Patryk Kala <[email protected]>
12
 */
13
class SymfonyCacheBridge implements CacheInterface
14
{
15
    /**
16
     * @var AdapterInterface
17
     */
18
    private $adapter;
19
20
    /**
21
     * @param AdapterInterface $adapter
22
     */
23 24
    public function __construct(AdapterInterface $adapter)
24
    {
25 24
        $this->adapter = $adapter;
26 24
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 4
    public function get($id)
32
    {
33 4
        $item = $this->adapter->getItem($id);
34 4
        if ($item->isHit()) {
35 4
            return $item->get();
36
        }
37
38 4
        return false;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 4
    public function has($id)
45
    {
46 4
        $item = $this->adapter->getItem($id);
47
48 4
        return $item->isHit();
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 4
    public function save($id, $data, $lifeTime = 0)
55
    {
56 4
        $item = $this->adapter->getItem($id);
57 4
        $item->set($data);
58
59 4
        if ($lifeTime > 0) {
60 4
            $item->expiresAfter($lifeTime);
61
        }
62
63 4
        return $this->adapter->save($item);
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 4
    public function delete($id)
70
    {
71 4
        $item = $this->adapter->getItem($id);
72
73 4
        return $this->adapter->deleteItem($item);
0 ignored issues
show
Documentation introduced by
$item is of type object<Symfony\Component\Cache\CacheItem>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
74
    }
75
}
76