TTtl   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 17
ccs 7
cts 7
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A timeToInt() 0 10 3
1
<?php
2
3
namespace kalanis\kw_cache_psr\Traits;
4
5
6
use DateTime;
7
use DateInterval;
8
use kalanis\kw_cache_psr\CacheException;
9
10
11
/**
12
 * Trait TTtl
13
 * @package kalanis\kw_cache_psr\Traits
14
 * Check time to live
15
 */
16
trait TTtl
17
{
18
    /**
19
     * @param DateInterval|int|null $time
20
     * @throws CacheException
21
     * @return int|null
22
     */
23 9
    protected function timeToInt($time): ?int
24
    {
25 9
        if (is_object($time)) {
26 2
            if ($time instanceof DateInterval) {
0 ignored issues
show
introduced by
$time is always a sub-type of DateInterval.
Loading history...
27 1
                $now = new DateTime();
28 1
                return $now->add($time)->getTimestamp();
29
            }
30 1
            throw new CacheException('Invalid object for time interval');
31
        }
32 7
        return $time;
33
    }
34
}
35