AssertPageTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 12
c 1
b 0
f 0
dl 0
loc 29
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A assertPage() 0 11 2
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * ReportingCloud PHP SDK
6
 *
7
 * PHP SDK 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://tinyurl.com/vmbbh6kd for the canonical source repository
11
 * @license   https://tinyurl.com/3pc9am89
12
 * @copyright © 2023 Text Control GmbH
13
 */
14
15
namespace TextControl\ReportingCloud\Assert;
16
17
/**
18
 * Trait AssertPageTrait
19
 */
20
trait AssertPageTrait
21
{
22
    use AssertRangeTrait;
23
    use ValueToStringTrait;
24
25
    /**
26
     * Minimum page number
27
     */
28
    private static int $pageMin = 1;
29
30
    /**
31
     * Maximum page number (PHP_INT_MAX)
32
     */
33
    private static int $pageMax = PHP_INT_MAX;
34
35
    /**
36
     * Check value is a valid page number
37
     */
38 16
    public static function assertPage(int $value, string $message = ''): void
39
    {
40 16
        $format  = '' === $message ? 'Page number (%1$s) must be in the range [%2$s..%3$s]' : $message;
41 16
        $message = sprintf(
42 16
            $format,
43 16
            self::valueToString($value),
44 16
            self::valueToString(self::$pageMin),
45 16
            self::valueToString(self::$pageMax)
46 16
        );
47
48 16
        self::assertRange($value, self::$pageMin, self::$pageMax, $message);
49
    }
50
}
51