Passed
Branch development-2.0 (f1893c)
by Jonathan
06:14
created

AssertTimestampTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 9
dl 0
loc 33
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A assertTimestamp() 0 9 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
 */
22
trait AssertTimestampTrait
23
{
24
    /**
25
     * Minimum timestamp (EPOC)
26
     *
27
     * @var int
28
     */
29
    private static $timestampMin = 0;
30
31
    /**
32
     * Maximum timestamp
33
     *
34
     * @var int
35
     */
36
    private static $timestampMax = PHP_INT_MAX;
37
38
    /**
39
     * Validate timestamp
40
     *
41
     * @param int    $value
42
     * @param string $message
43
     *
44
     * @return null
45
     */
46 58
    public static function assertTimestamp(int $value, string $message = '')
47
    {
48 58
        $format  = 'Timestamp (%s) must be in the range [%2$s..%3$s]';
49 58
        $message = sprintf($message ?: $format,
50 58
                           static::valueToString($value),
51 58
                           static::valueToString(static::$timestampMin),
0 ignored issues
show
Bug introduced by
Since $timestampMin is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $timestampMin to at least protected.
Loading history...
52 58
                           static::valueToString(static::$timestampMax));
0 ignored issues
show
Bug introduced by
Since $timestampMax is declared private, accessing it with static will lead to errors in possible sub-classes; you can either use self, or increase the visibility of $timestampMax to at least protected.
Loading history...
53
54 58
        return static::range($value, static::$timestampMin, static::$timestampMax, $message);
55
    }
56
}
57