Completed
Push — 2.0 ( aed067...b26523 )
by Marco
04:31
created

TtlTrait::setTtl()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 8

Duplication

Lines 19
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 3.0175

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 19
loc 19
ccs 7
cts 8
cp 0.875
rs 9.4285
cc 3
eloc 8
nc 3
nop 1
crap 3.0175
1
<?php namespace Comodojo\Cache\Components;
2
3
use \Comodojo\Exception\CacheException;
4
5
/**
6
 * Cache provider interface
7
 *
8
 * @package     Comodojo Spare Parts
9
 * @author      Marco Giovinazzi <[email protected]>
10
 * @license     MIT
11
 *
12
 * LICENSE:
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
 * THE SOFTWARE.
21
 */
22
23 View Code Duplication
trait TtlTrait {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
25
    /**
26
     * Default cache ttl
27
     *
28
     * @var int
29
     */
30
    public static $default_ttl = 3600;
31
32
    /**
33
     * Cache ttl (in seconds)
34
     *
35
     * @var int
36
     */
37
    protected $ttl;
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 6
    final public function getTtl() {
43
44 6
        return $this->ttl;
45
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 113
    public function setTtl($ttl = null) {
52
53 113
        if ( is_null($ttl) ) {
54
55 107
            $this->ttl = self::$default_ttl;
56
57 113
        } else if ( is_int($ttl) ) {
58
59 17
            $this->ttl = $ttl;
60
61 17
        } else {
62
63
            throw new CacheException("Invalid time to live");
64
65
        }
66
67 113
        return $this;
68
69
    }
70
71
}
72