SubKey   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 42.86%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 0
dl 0
loc 70
ccs 9
cts 21
cp 0.4286
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getPatternCacheSubkey() 0 4 1
A getAllPatternCacheSubkeys() 0 13 3
A getIniPartCacheSubKey() 0 4 1
A getAllIniPartCacheSubKeys() 0 15 4
1
<?php
2
declare(strict_types = 1);
3
4
namespace BrowscapPHP\Parser\Helper;
5
6
/**
7
 * includes general functions for the work with patterns
8
 */
9
final class SubKey
10
{
11
    private function __construct()
12
    {
13
    }
14
15
    /**
16
     * Gets the subkey for the pattern cache file, generated from the given string
17
     *
18
     * @param  string $string
19
     *
20
     * @return string
21
     */
22 1
    public static function getPatternCacheSubkey(string $string) : string
23
    {
24 1
        return $string[0] . $string[1];
25
    }
26
27
    /**
28
     * Gets all subkeys for the pattern cache files
29
     *
30
     * @return string[]
31
     */
32 1
    public static function getAllPatternCacheSubkeys() : array
33
    {
34 1
        $subkeys = [];
35 1
        $chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
36
37 1
        foreach ($chars as $charOne) {
38 1
            foreach ($chars as $charTwo) {
39 1
                $subkeys[$charOne . $charTwo] = '';
40
            }
41
        }
42
43 1
        return $subkeys;
44
    }
45
46
    /**
47
     * Gets the sub key for the ini parts cache file, generated from the given string
48
     *
49
     * @param  string $string
50
     *
51
     * @return string
52
     */
53
    public static function getIniPartCacheSubKey(string $string) : string
54
    {
55
        return $string[0] . $string[1] . $string[2];
56
    }
57
58
    /**
59
     * Gets all sub keys for the inipart cache files
60
     *
61
     * @return string[]
62
     */
63
    public static function getAllIniPartCacheSubKeys() : array
64
    {
65
        $subKeys = [];
66
        $chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
67
68
        foreach ($chars as $charOne) {
69
            foreach ($chars as $charTwo) {
70
                foreach ($chars as $charThree) {
71
                    $subKeys[] = $charOne . $charTwo . $charThree;
72
                }
73
            }
74
        }
75
76
        return $subKeys;
77
    }
78
}
79