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

AssertPageTrait   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 assertPage() 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 AssertPageTrait
19
 *
20
 * @package TxTextControl\ReportingCloud
21
 */
22
trait AssertPageTrait
23
{
24
    /**
25
     * Minimum page number
26
     *
27
     * @var int
28
     */
29
    private static $pageMin = 1;
30
31
    /**
32
     * Maximum page number
33
     *
34
     * @var int
35
     */
36
    private static $pageMax = PHP_INT_MAX;
37
38
    /**
39
     * Validate page
40
     *
41
     * @param int    $value
42
     * @param string $message
43
     *
44
     * @return null
45
     */
46 7
    public static function assertPage(int $value, string $message = '')
47
    {
48 7
        $format  = 'Page number (%s) must be in the range [%2$s..%3$s]';
49 7
        $message = sprintf($message ?: $format,
50 7
                           static::valueToString($value),
51 7
                           static::valueToString(static::$pageMin),
0 ignored issues
show
Bug introduced by
Since $pageMin 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 $pageMin to at least protected.
Loading history...
52 7
                           static::valueToString(static::$pageMax));
0 ignored issues
show
Bug introduced by
Since $pageMax 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 $pageMax to at least protected.
Loading history...
53
54 7
        return static::range($value, static::$pageMin, static::$pageMax, $message);
55
    }
56
}
57