AssertPageTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
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 39
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://git.io/Jejj2 for the canonical source repository
11
 * @license   https://git.io/Jejjr
12
 * @copyright © 2022 Text Control GmbH
13
 */
14
15
namespace TxTextControl\ReportingCloud\Assert;
16
17
use TxTextControl\ReportingCloud\Exception\InvalidArgumentException;
18
19
/**
20
 * Trait AssertPageTrait
21
 *
22
 * @package TxTextControl\ReportingCloud
23
 * @author  Jonathan Maron (@JonathanMaron)
24
 */
25
trait AssertPageTrait
26
{
27
    use ValueToStringTrait;
28
    use AssertRangeTrait;
29
30
    /**
31
     * Minimum page number
32
     *
33
     * @var int
34
     */
35
    private static int $pageMin = 1;
36
37
    /**
38
     * Maximum page number (PHP_INT_MAX)
39
     *
40
     * @var int
41
     */
42
    private static int $pageMax = PHP_INT_MAX;
43
44
    /**
45
     * Check value is a valid page number
46
     *
47
     * @param int    $value
48
     * @param string $message
49
     *
50
     * @return void
51
     * @throws InvalidArgumentException
52
     */
53 16
    public static function assertPage(int $value, string $message = ''): void
54
    {
55 16
        $format  = 0 === strlen($message) ? 'Page number (%1$s) must be in the range [%2$s..%3$s]' : $message;
56 16
        $message = sprintf(
57 16
            $format,
58 16
            self::valueToString($value),
59 16
            self::valueToString(self::$pageMin),
60 16
            self::valueToString(self::$pageMax)
61 16
        );
62
63 16
        self::assertRange($value, self::$pageMin, self::$pageMax, $message);
64
    }
65
}
66