FallbackAwareTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 38
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasFallback() 0 7 3
A getFallback() 0 4 1
A setFallback() 0 5 1
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Cache
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Cache\Traits;
16
17
use Phossa2\Cache\Interfaces\DriverInterface;
18
use Phossa2\Cache\Interfaces\FallbackAwareInterface;
19
20
/**
21
 * FallbackAwareTrait
22
 *
23
 * @package Phossa2\Cache
24
 * @author  Hong Zhang <[email protected]>
25
 * @see     FallbackAwareInterface
26
 * @version 2.0.0
27
 * @since   2.0.0 added
28
 */
29
trait FallbackAwareTrait
30
{
31
    /**
32
     * Fallback cache driver (normally slower)
33
     *
34
     * @var    DriverInterface
35
     * @access protected
36
     */
37
    protected $fallback;
38
39
    /**
40
     * {@inheritDoc}
41
     */
42
    public function hasFallback()/*# : bool */
43
    {
44
        if (!is_null($this->fallback) && $this->fallback->ping()) {
45
            return true;
46
        }
47
        return false;
48
    }
49
50
    /**
51
     * {@inheritDoc}
52
     */
53
    public function getFallback()/*# : DriverInterface */
54
    {
55
        return $this->fallback;
56
    }
57
58
    /**
59
     * {@inheritDoc}
60
     */
61
    public function setFallback(DriverInterface $driver)
62
    {
63
        $this->fallback = $driver;
64
        return $this;
65
    }
66
}
67