KeyUtil::validateMultiple()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.2
cc 4
eloc 4
nc 3
nop 1
crap 4
1
<?php
2
3
/*
4
 * This file is part of the webmozart/key-value-store package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webmozart\KeyValueStore\Util;
13
14
use Webmozart\KeyValueStore\Api\InvalidKeyException;
15
16
/**
17
 * Utility methods for dealing with key-value store keys.
18
 *
19
 * @since  1.0
20
 *
21
 * @author Bernhard Schussek <[email protected]>
22
 */
23
final class KeyUtil
24
{
25
    /**
26
     * Validates that a key is valid.
27
     *
28
     * @param mixed $key The tested key.
29
     *
30
     * @throws InvalidKeyException If the key is invalid.
31
     */
32 856
    public static function validate($key)
33
    {
34 856
        if (!is_string($key) && !is_int($key)) {
35 114
            throw InvalidKeyException::forKey($key);
36
        }
37 746
    }
38
39
    /**
40
     * Validates that multiple keys are valid.
41
     *
42
     * @param array $keys The tested keys.
43
     *
44
     * @throws InvalidKeyException If a key is invalid.
45
     */
46 369
    public static function validateMultiple($keys)
47
    {
48 369
        foreach ($keys as $key) {
49 369
            if (!is_string($key) && !is_int($key)) {
50 369
                throw InvalidKeyException::forKey($key);
51
            }
52
        }
53 329
    }
54
55
    private function __construct()
56
    {
57
    }
58
}
59