Completed
Push — min-php71 ( f5a25a )
by James
05:53
created

SubKey   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 42.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
lcom 0
cbo 0
dl 0
loc 68
ccs 9
cts 21
cp 0.4286
rs 10
c 1
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
     * @return string
20
     */
21 2
    public static function getPatternCacheSubkey(string $string) : string
22
    {
23 2
        return $string[0] . $string[1];
24
    }
25
26
    /**
27
     * Gets all subkeys for the pattern cache files
28
     *
29
     * @return array
30
     */
31 1
    public static function getAllPatternCacheSubkeys() : array
32
    {
33 1
        $subkeys = [];
34 1
        $chars   = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
35
36 1
        foreach ($chars as $charOne) {
37 1
            foreach ($chars as $charTwo) {
38 1
                $subkeys[$charOne . $charTwo] = '';
39
            }
40
        }
41
42 1
        return $subkeys;
43
    }
44
45
    /**
46
     * Gets the sub key for the ini parts cache file, generated from the given string
47
     *
48
     * @param  string $string
49
     * @return string
50
     */
51
    public static function getIniPartCacheSubKey(string $string) : string
52
    {
53
        return $string[0] . $string[1] . $string[2];
54
    }
55
56
    /**
57
     * Gets all sub keys for the inipart cache files
58
     *
59
     * @return array
60
     */
61
    public static function getAllIniPartCacheSubKeys() : array
62
    {
63
        $subKeys = [];
64
        $chars   = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
65
66
        foreach ($chars as $charOne) {
67
            foreach ($chars as $charTwo) {
68
                foreach ($chars as $charThree) {
69
                    $subKeys[] = $charOne . $charTwo . $charThree;
70
                }
71
            }
72
        }
73
74
        return $subKeys;
75
    }
76
}
77