TTLValidatorTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateTTL() 0 15 4
1
<?php
2
3
namespace SubjectivePHP\Psr\SimpleCache;
4
5
/**
6
 * Trait for validating PSR-16 simple cache expiress.
7
 */
8
trait TTLValidatorTrait
9
{
10
    /**
11
     * Verifies the the given cache expires is a legal value.
12
     *
13
     * @param mixed $ttl The cache ttl value to validate.
14
     *
15
     * @return void
16
     *
17
     * @throws InvalidArgumentException Thrown if $ttl is not null, integer or a \DateInterval instance
18
     */
19
    protected function validateTTL($ttl)
20
    {
21
        if ($ttl === null) {
22
            return;
23
        }
24
25
        if ($ttl instanceof \DateInterval) {
26
            return;
27
        }
28
29
        if (is_int($ttl)) {
30
            return;
31
        }
32
33
        throw new InvalidArgumentException('$ttl must be null, an integer or \DateInterval instance');
34
    }
35
}
36