Passed
Pull Request — master (#88)
by Arman
06:12 queued 03:03
created

Cache::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.8.0
13
 */
14
15
namespace Quantum\Libraries\Cache;
16
17
use Quantum\Exceptions\CacheException;
18
use Psr\SimpleCache\CacheInterface;
19
20
/**
21
 * Class Cache
22
 * @package Quantum\Libraries\Cache
23
 * @method mixed get($key, $default = null)
24
 * @method array getMultiple($keys, $default = null)
25
 * @method has($key): bool
26
 * @method bool set($key, $value, $ttl = null)
27
 * @method bool setMultiple($values, $ttl = null)
28
 * @method bool delete($key)
29
 * @method bool deleteMultiple($keys)
30
 * @method bool clear()
31
 */
32
class Cache
33
{
34
35
    /**
36
     * @var Psr\SimpleCache\CacheInterface
0 ignored issues
show
Bug introduced by
The type Quantum\Libraries\Cache\...pleCache\CacheInterface was not found. Did you mean Psr\SimpleCache\CacheInterface? If so, make sure to prefix the type with \.
Loading history...
37
     */
38
    private $adapter;
39
40
    /**
41
     * Cache constructor
42
     * @param Psr\SimpleCache\CacheInterface $cacheAdapter
43
     */
44
    public function __construct(CacheInterface $cacheAdapter)
45
    {
46
        $this->adapter = $cacheAdapter;
0 ignored issues
show
Documentation Bug introduced by
It seems like $cacheAdapter of type Psr\SimpleCache\CacheInterface is incompatible with the declared type Quantum\Libraries\Cache\...pleCache\CacheInterface of property $adapter.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
47
    }
48
49
    /**
50
     * Gets the current adapter
51
     * @return Psr\SimpleCache\CacheInterface
52
     */
53
    public function getAdapter(): CacheInterface
54
    {
55
        return $this->adapter;
56
    }
57
58
    /**
59
     * @param string $method
60
     * @param array|null $arguments
61
     * @return mixed
62
     * @throws \Quantum\Exceptions\AppException
63
     */
64
    public function __call(string $method, ?array $arguments)
65
    {
66
        if (!method_exists($this->adapter, $method)) {
67
            throw CacheException::methodNotSupported($method, get_class($this->adapter));
68
        }
69
70
        return $this->adapter->$method(...$arguments);
71
    }
72
73
}
74