TtlTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 30
ccs 6
cts 6
cp 1
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setTtlOption() 0 7 3
A getTtlOption() 0 3 1
1
<?php
2
/**
3
 * This file is part of the Cache package.
4
 *
5
 * Copyright (c) Daniel González
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author Daniel González <[email protected]>
11
 * @author Arnold Daniels <[email protected]>
12
 */
13
14
declare(strict_types=1);
15
16
namespace Desarrolla2\Cache\Option;
17
18
use Desarrolla2\Cache\Exception\InvalidArgumentException;
19
20
/**
21
 * TTL option
22
 */
23
trait TtlTrait
24
{
25
    /**
26
     * @var int|null
27
     */
28
    protected $ttl = null;
29
30
    /**
31
     * Set the maximum time to live (ttl)
32
     *
33
     * @param int|null $value  Seconds or null to live forever
34
     * @throws InvalidArgumentException
35
     */
36 34
    protected function setTtlOption(?int $value): void
37
    {
38 34
        if (isset($value) && $value < 1) {
39 11
            throw new InvalidArgumentException('ttl cant be lower than 1');
40
        }
41
42 23
        $this->ttl = $value;
43
    }
44
45
    /**
46
     * Get the maximum time to live (ttl)
47
     *
48
     * @return int|null
49
     */
50 23
    protected function getTtlOption(): ?int
51
    {
52 23
        return $this->ttl;
53
    }
54
}