Passed
Push — master ( 71c3b0...2166ef )
by Jonathan
13:15
created

AssertTimestampTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 10
dl 0
loc 36
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A assertTimestamp() 0 11 2
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * ReportingCloud PHP Wrapper
6
 *
7
 * PHP wrapper for ReportingCloud Web API. Authored and supported by Text Control GmbH.
8
 *
9
 * @link      https://www.reporting.cloud to learn more about ReportingCloud
10
 * @link      https://github.com/TextControl/txtextcontrol-reportingcloud-php for the canonical source repository
11
 * @license   https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-php/master/LICENSE.md
12
 * @copyright © 2019 Text Control GmbH
13
 */
14
15
namespace TxTextControl\ReportingCloud\Assert;
16
17
/**
18
 * Trait AssertTimestampTrait
19
 *
20
 * @package TxTextControl\ReportingCloud
21
 * @author  Jonathan Maron (@JonathanMaron)
22
 */
23
trait AssertTimestampTrait
24
{
25
    /**
26
     * Minimum timestamp (EPOC)
27
     *
28
     * @var int
29
     */
30
    private static $timestampMin = 0;
31
32
    /**
33
     * Maximum timestamp
34
     *
35
     * @var int
36
     */
37
    private static $timestampMax = PHP_INT_MAX;
38
39
    /**
40
     * Validate timestamp
41
     *
42
     * @param int    $value
43
     * @param string $message
44
     *
45
     * @return null
46
     * @throws \TxTextControl\ReportingCloud\Exception\InvalidArgumentException
47
     */
48 39
    public static function assertTimestamp(int $value, string $message = '')
49
    {
50 39
        $format  = $message ?: 'Timestamp (%s) must be in the range [%2$s..%3$s]';
51 39
        $message = sprintf(
52 39
            $format,
53 39
            self::valueToString($value),
54 39
            self::valueToString(self::$timestampMin),
55 39
            self::valueToString(self::$timestampMax)
56
        );
57
58 39
        return self::range($value, self::$timestampMin, self::$timestampMax, $message);
59
    }
60
}
61