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