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

TtlTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 90%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 1
dl 49
loc 49
ccs 9
cts 10
cp 0.9
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTtl() 5 5 1
A setTtl() 19 19 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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