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