Apc   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A flush() 0 17 1
A __construct() 0 3 1
1
<?php
2
3
namespace MatthiasMullie\Scrapbook\Adapters\Collections;
4
5
use MatthiasMullie\Scrapbook\Adapters\Apc as Adapter;
6
use MatthiasMullie\Scrapbook\Adapters\Collections\Utils\PrefixKeys;
7
8
/**
9
 * APC adapter for a subset of data, accomplished by prefixing keys.
10
 *
11
 * @author Matthias Mullie <[email protected]>
12
 * @copyright Copyright (c) 2014, Matthias Mullie. All rights reserved
13
 * @license LICENSE MIT
14
 */
15
class Apc extends PrefixKeys
16
{
17
    /**
18
     * @param string $name
19
     */
20
    public function __construct(Adapter $cache, $name)
21
    {
22
        parent::__construct($cache, 'collection:'.$name.':');
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function flush()
29
    {
30
        /*
31
         * Both of these utility methods are protected in parent, because I just
32
         * don't want to expose them to users. But I really want to use them
33
         * here... I'll use reflection to access them - I shouldn't, but I have
34
         * a decent test suite to protect me, should I forget about this and
35
         * change the implementation of these methods.
36
         */
37
        $reflection = new \ReflectionMethod($this->cache, 'APCuIterator');
38
        $reflection->setAccessible(true);
39
        $iterator = $reflection->invoke($this->cache, '/^'.preg_quote($this->prefix, '/').'/', \APC_ITER_KEY);
40
41
        $reflection = new \ReflectionMethod($this->cache, 'apcu_delete');
42
        $reflection->setAccessible(true);
43
44
        return $reflection->invoke($this->cache, $iterator);
45
    }
46
}
47