TtlTrait::setTtlOption()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 3
rs 10
c 1
b 0
f 0
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
}