Passed
Branch development-2.0 (469a91)
by Jonathan
04:44
created

AssertZoomFactorTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 2
eloc 11
dl 0
loc 37
ccs 8
cts 9
cp 0.8889
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A assertZoomFactor() 0 12 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
 * @author  Jonathan Maron (@JonathanMaron)
22
 */
23
trait AssertZoomFactorTrait
24
{
25
    /**
26
     * Minimum zoom factor
27
     *
28
     * @var int
29
     */
30
    private static $zoomFactorMin = 1;
31
32
    /**
33
     * Maximum zoom factor
34
     *
35
     * @var int
36
     */
37
    private static $zoomFactorMax = 400;
38
39
    /**
40
     * Validate zoom factor
41
     *
42
     * @param int    $value
43
     * @param string $message
44
     *
45
     * @return null
46
     * @throws \TxTextControl\ReportingCloud\Exception\InvalidArgumentException
47
     */
48 8
    public static function assertZoomFactor(int $value, string $message = '')
49
    {
50 8
        $format  = 'Zoom factor (%s) must be in the range [%2$s..%3$s]';
51 8
        $message = sprintf(
52
            $message ?:
53 8
            $format,
54 8
            self::valueToString($value),
55 8
            self::valueToString(self::$zoomFactorMin),
56 8
            self::valueToString(self::$zoomFactorMax)
57
        );
58
59 8
        return self::range($value, self::$zoomFactorMin, self::$zoomFactorMax, $message);
60
    }
61
}
62