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

AssertZoomFactorTrait::assertZoomFactor()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 9
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 1
nop 2
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace TxTextControl\ReportingCloud\Assert;
5
6
/**
7
 * ReportingCloud PHP Wrapper
8
 *
9
 * PHP wrapper for ReportingCloud Web API. Authored and supported by Text Control GmbH.
10
 *
11
 * @link      https://www.reporting.cloud to learn more about ReportingCloud
12
 * @link      https://github.com/TextControl/txtextcontrol-reportingcloud-php for the canonical source repository
13
 * @license   https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-php/master/LICENSE.md
14
 * @copyright © 2019 Text Control GmbH
15
 */
16
17
/**
18
 * Trait AssertZoomFactorTrait
19
 *
20
 * @package TxTextControl\ReportingCloud
21
 */
22
trait AssertZoomFactorTrait
23
{
24
    /**
25
     * Minimum zoom factor
26
     *
27
     * @var int
28
     */
29
    private static $zoomFactorMin = 1;
30
31
    /**
32
     * Maximum zoom factor
33
     *
34
     * @var int
35
     */
36
    private static $zoomFactorMax = 400;
37
38
    /**
39
     * Validate zoom factor
40
     *
41
     * @param int    $value
42
     * @param string $message
43
     *
44
     * @return null
45
     */
46 8
    public static function assertZoomFactor(int $value, string $message = '')
47
    {
48 8
        $format  = 'Zoom factor (%s) must be in the range [%2$s..%3$s]';
49 8
        $message = sprintf($message ?: $format,
50 8
                           static::valueToString($value),
51 8
                           static::valueToString(static::$zoomFactorMin),
0 ignored issues
show
Bug introduced by
Since $zoomFactorMin 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 $zoomFactorMin to at least protected.
Loading history...
52 8
                           static::valueToString(static::$zoomFactorMax));
0 ignored issues
show
Bug introduced by
Since $zoomFactorMax 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 $zoomFactorMax to at least protected.
Loading history...
53
54 8
        return static::range($value, static::$zoomFactorMin, static::$zoomFactorMax, $message);
55
    }
56
}
57