ApcuDriver   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 3 1
A connect() 0 3 1
A clear() 0 3 1
A __construct() 0 7 2
A check() 0 7 3
1
<?php
2
/**
3
 * This file is part of the InMemoryList package.
4
 *
5
 * (c) Mauro Cassani<https://github.com/mauretto78>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 */
10
11
namespace InMemoryList\Infrastructure\Drivers;
12
13
use InMemoryList\Infrastructure\Drivers\Contracts\DriverInterface;
14
use InMemoryList\Infrastructure\Drivers\Exceptions\ApcuDriverCheckException;
15
16
class ApcuDriver implements DriverInterface
17
{
18
    /**
19
     * ApcuDriver constructor.
20
     *
21
     * @codeCoverageIgnore
22
     *
23
     * @throws ApcuDriverCheckException
24
     */
25
    public function __construct()
26
    {
27
        if (!$this->check()) {
28
            throw new ApcuDriverCheckException('Apcu extension is not loaded.');
29
        }
30
31
        $this->connect();
32
    }
33
34
    /**
35
     * @codeCoverageIgnore
36
     *
37
     * @return bool
38
     */
39
    public function check()
40
    {
41
        if (extension_loaded('apcu') && ini_get('apc.enabled')) {
42
            return true;
43
        }
44
45
        return false;
46
    }
47
48
    /**
49
     * @return bool
50
     */
51
    public function clear()
52
    {
53
        return apcu_clear_cache();
54
    }
55
56
    /**
57
     * @return bool
58
     */
59
    public function connect()
60
    {
61
        return true;
62
    }
63
64
    /**
65
     * @return mixed
66
     */
67
    public function getInstance()
68
    {
69
        return $this;
70
    }
71
}
72