AssertPageTrait::assertPage()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 11
ccs 9
cts 9
cp 1
rs 10
cc 2
nc 2
nop 2
crap 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