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

SubKey::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 2
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