Passed
Push — v7 ( ebd842...f31319 )
by Georges
01:32
created

PhpfastcacheAbstractProxy   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 7 2
A __construct() 0 3 1
1
<?php
2
/**
3
 *
4
 * This file is part of phpFastCache.
5
 *
6
 * @license MIT License (MIT)
7
 *
8
 * For full copyright and license information, please see the docs/CREDITS.txt file.
9
 *
10
 * @author Khoa Bui (khoaofgod)  <[email protected]> http://www.phpfastcache.com
11
 * @author Georges.L (Geolim4)  <[email protected]>
12
 *
13
 */
14
declare(strict_types=1);
15
16
namespace Phpfastcache\Proxy;
17
18
use Phpfastcache\CacheManager;
19
use Phpfastcache\Core\Item\ExtendedCacheItemInterface;
20
use Phpfastcache\Entities\DriverStatistic;
21
use Psr\Cache\CacheItemInterface;
22
23
/**
24
 * Class phpFastCache
25
 *
26
 * Handle methods using annotations for IDE
27
 * because they're handled by __call()
28
 * Check out ExtendedCacheItemInterface to see all
29
 * the drivers methods magically implemented
30
 *
31
 * @method ExtendedCacheItemInterface getItem($key) Retrieve an item and returns an empty item if not found
32
 * @method ExtendedCacheItemInterface[] getItems(array $keys) Retrieve an item and returns an empty item if not found
33
 * @method bool hasItem() hasItem($key) Tests if an item exists
34
 * @method bool deleteItem(string $key) Delete an item
35
 * @method bool deleteItems(array $keys) Delete some items
36
 * @method bool save(CacheItemInterface $item) Save an item
37
 * @method bool saveDeferred(CacheItemInterface $item) Sets a cache item to be persisted later
38
 * @method bool commit() Persists any deferred cache items
39
 * @method bool clear() Allow you to completely empty the cache and restart from the beginning
40
 * @method DriverStatistic stats() Returns a DriverStatistic object
41
 * @method ExtendedCacheItemInterface getItemsByTag($tagName) Return items by a tag
42
 * @method ExtendedCacheItemInterface[] getItemsByTags(array $tagNames) Return items by some tags
43
 * @method bool deleteItemsByTag($tagName) Delete items by a tag
44
 * @method bool deleteItemsByTags(array $tagNames) // Delete items by some tags
45
 * @method void incrementItemsByTag($tagName, $step = 1) // Increment items by a tag
46
 * @method void incrementItemsByTags(array $tagNames, $step = 1) // Increment items by some tags
47
 * @method void decrementItemsByTag($tagName, $step = 1) // Decrement items by a tag
48
 * @method void decrementItemsByTags(array $tagNames, $step = 1) // Decrement items by some tags
49
 * @method void appendItemsByTag($tagName, $data) // Append items by a tag
50
 * @method void appendItemsByTags(array $tagNames, $data) // Append items by a tags
51
 * @method void prependItemsByTag($tagName, $data) // Prepend items by a tag
52
 * @method void prependItemsByTags(array $tagNames, $data) // Prepend items by a tags
53
 */
54
abstract class PhpfastcacheAbstractProxy
55
{
56
    /**
57
     * @var \Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface
58
     */
59
    protected $instance;
60
61
    /**
62
     * PhpfastcacheAbstractProxy constructor.
63
     * @param string $driver
64
     * @param array|\Phpfastcache\Config\ConfigurationOption $config
65
     */
66
    public function __construct($driver = 'auto', $config = null)
67
    {
68
        $this->instance = CacheManager::getInstance($driver, $config);
69
    }
70
71
    /**
72
     * @param $name
73
     * @param $args
74
     * @return mixed
75
     * @throws \BadMethodCallException
76
     */
77
    public function __call($name, $args)
78
    {
79
        if (method_exists($this->instance, $name)) {
80
            return call_user_func_array([$this->instance, $name], $args);
81
        }
82
83
        throw new \BadMethodCallException(sprintf('Method %s does not exists', $name));
84
    }
85
}
86