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

AssertApiKeyTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 10
dl 0
loc 35
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A assertApiKey() 0 11 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 AssertApiKeyTrait
19
 *
20
 * @package TxTextControl\ReportingCloud
21
 */
22
trait AssertApiKeyTrait
23
{
24
    /**
25
     * Minimum length of API key
26
     *
27
     * @var int
28
     */
29
    private static $apiKeyMinLength = 20;
30
31
    /**
32
     * Maximum length of API key
33
     *
34
     * @var int
35
     */
36
    private static $apiKeyMaxLength = 45;
37
38
    /**
39
     * Validate length of API key
40
     *
41
     * @param string $value
42
     * @param string $message
43
     *
44
     * @return null
45
     */
46 7
    public static function assertApiKey(string $value, string $message = '')
47
    {
48 7
        $length = strlen($value);
49
50 7
        $format  = 'Length of API key (%s) must be in the range [%2$s..%3$s]';
51 7
        $message = sprintf($message ?: $format,
52 7
                           static::valueToString($value),
53 7
                           static::valueToString(static::$apiKeyMinLength),
0 ignored issues
show
Bug introduced by
Since $apiKeyMinLength 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 $apiKeyMinLength to at least protected.
Loading history...
54 7
                           static::valueToString(static::$apiKeyMaxLength));
0 ignored issues
show
Bug introduced by
Since $apiKeyMaxLength 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 $apiKeyMaxLength to at least protected.
Loading history...
55
56 7
        return static::range($length, static::$apiKeyMinLength, static::$apiKeyMaxLength, $message);
57
    }
58
}
59