Completed
Push — master ( e54095...b55a89 )
by Mr
02:48
created

Helpers   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 34
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isCertAllowed() 0 6 2
A decamelize() 0 9 3
1
<?php
2
3
namespace OpenVPN;
4
5
use RuntimeException;
6
7
/**
8
 * Class Helpers
9
 *
10
 * @package OpenVPN
11
 * @since   1.0.0
12
 */
13
class Helpers
14
{
15
    /**
16
     * Check if provided type of certs is allowed
17
     *
18
     * @param string $key
19
     *
20
     * @throws \RuntimeException
21
     */
22 6
    public static function isCertAllowed(string $key): void
23
    {
24 6
        if (!in_array($key, Config::ALLOWED_TYPES_OF_CERTS, true)) {
25
            throw new RuntimeException("Key '$key' not in list of allowed [" . implode(',', Config::ALLOWED_TYPES_OF_CERTS) . ']');
26
        }
27 6
    }
28
29
    /**
30
     * Convert string like "makeMeHappy" to "make-me-happy"
31
     *
32
     * @param string $input
33
     *
34
     * @return string
35
     */
36 3
    public static function decamelize(string $input): string
37
    {
38 3
        preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches);
39 3
        $result = $matches[0];
40 3
        foreach ($result as &$match) {
41 3
            $match = $match === strtoupper($match) ? strtolower($match) : lcfirst($match);
42
        }
43 3
        return implode('-', $result);
44
    }
45
46
}
47