QueueUtils   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 0
dl 0
loc 43
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A normalizeEta() 0 17 6
A calculateDelay() 0 10 3
1
<?php
2
3
/*
4
 * This file is part of the Phive Queue package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Phive\Queue;
13
14
abstract class QueueUtils
15
{
16
    /**
17
     * @param mixed $eta
18
     *
19
     * @return int The Unix timestamp.
20
     *
21
     * @throws \InvalidArgumentException
22
     */
23 145
    public static function normalizeEta($eta)
24
    {
25 145
        if (null === $eta) {
26 108
            return time();
27
        }
28 44
        if (is_string($eta)) {
29 16
            $eta = date_create($eta);
30 16
        }
31 44
        if ($eta instanceof \DateTime || $eta instanceof \DateTimeInterface) {
32 17
            return $eta->getTimestamp();
33
        }
34 27
        if (is_int($eta)) {
35 24
            return $eta;
36
        }
37
38 3
        throw new \InvalidArgumentException('The eta parameter is not valid.');
39
    }
40
41
    /**
42
     * @param mixed $eta
43
     *
44
     * @return int
45
     */
46 35
    public static function calculateDelay($eta)
47
    {
48 35
        if (null === $eta) {
49 24
            return 0;
50
        }
51
52 13
        $delay = -time() + self::normalizeEta($eta);
53
54 13
        return ($delay < 0) ? 0 : $delay;
55
    }
56
}
57