Passed
Push — master ( 48948a...a5130b )
by Christian
02:28
created

APCu::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RemotelyLiving\PHPCacheAdapter\SimpleCache;
6
7
use Psr\SimpleCache;
8
use RemotelyLiving\PHPCacheAdapter\Assertions;
9
10
final class APCu extends AbstractAdapter
11
{
12
    private function __construct()
13
    {
14
        Assertions::assertExtensionLoaded('apcu');
15
        ini_set('apc.use_request_time', '0');
16
    }
17
18
    public static function create(): SimpleCache\CacheInterface
19
    {
20
        return new self();
21
    }
22
23
    public function flush(): bool
24
    {
25
        return \apcu_clear_cache();
26
    }
27
28
    /**
29
     * @inheritDoc
30
     * @psalm-suppress InvalidArgument MoreSpecificImplementedParamType
31
     */
32
    protected function multiGet(array $keys, $default = null): \Generator
33
    {
34
        $results = \apcu_fetch($keys);
35
        foreach ($keys as $key) {
36
            yield $key => $results[$key] ?? $default;
37
        }
38
    }
39
40
    protected function multiSave(array $values, int $ttl = null): bool
41
    {
42
        \apcu_store($values, null, (int) $ttl);
43
44
        return true;
45
    }
46
47
    protected function multiDelete(array $keys): bool
48
    {
49
        return \apcu_delete(new \APCUIterator($keys));
0 ignored issues
show
Bug Best Practice introduced by
The expression return apcu_delete(new APCUIterator($keys)) could return the type string[] which is incompatible with the type-hinted return boolean. Consider adding an additional type-check to rule them out.
Loading history...
50
    }
51
52
    protected function exists(string $key): bool
53
    {
54
        return \apcu_exists($key);
0 ignored issues
show
Bug Best Practice introduced by
The expression return apcu_exists($key) could return the type string[] which is incompatible with the type-hinted return boolean. Consider adding an additional type-check to rule them out.
Loading history...
55
    }
56
}
57