TCheckKey   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 36
ccs 18
cts 18
cp 1
rs 10
wmc 9

1 Method

Rating   Name   Duplication   Size   Complexity  
B checkKey() 0 29 9
1
<?php
2
3
namespace kalanis\kw_cache_psr\Traits;
4
5
6
use kalanis\kw_cache_psr\InvalidArgumentException;
7
8
9
/**
10
 * Trait TCheckKey
11
 * @package kalanis\kw_cache_psr\Traits
12
 * Check key for problematic characters
13
 */
14
trait TCheckKey
15
{
16
    /**
17
     * @param string $key
18
     * @return string
19
     * @throws InvalidArgumentException
20
     */
21 48
    protected function checkKey(string $key): string
22
    {
23
        // problematic chars
24
        // {}()/\@:
25 48
        if (false !== strpos($key, '{')) {
26 7
            throw new InvalidArgumentException(sprintf('The key *%s* contains "{"', $key));
27
        }
28 43
        if (false !== strpos($key, '}')) {
29 1
            throw new InvalidArgumentException(sprintf('The key *%s* contains "}"', $key));
30
        }
31 42
        if (false !== strpos($key, '(')) {
32 1
            throw new InvalidArgumentException(sprintf('The key *%s* contains "("', $key));
33
        }
34 41
        if (false !== strpos($key, ')')) {
35 1
            throw new InvalidArgumentException(sprintf('The key *%s* contains ")"', $key));
36
        }
37 40
        if (false !== strpos($key, '/')) {
38 1
            throw new InvalidArgumentException(sprintf('The key *%s* contains "/"', $key));
39
        }
40 39
        if (false !== strpos($key, '\\')) {
41 1
            throw new InvalidArgumentException(sprintf('The key *%s* contains "\\"', $key));
42
        }
43 38
        if (false !== strpos($key, '@')) {
44 1
            throw new InvalidArgumentException(sprintf('The key *%s* contains "@"', $key));
45
        }
46 37
        if (false !== strpos($key, ':')) {
47 1
            throw new InvalidArgumentException(sprintf('The key *%s* contains ":"', $key));
48
        }
49 36
        return $key;
50
    }
51
}
52