StringHelper   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 52
ccs 20
cts 20
cp 1
rs 10
wmc 11

10 Methods

Rating   Name   Duplication   Size   Complexity  
A contains() 0 3 1
A toSnakeCase() 0 3 1
A toKebabCase() 0 3 1
A makePrefix() 0 5 2
A toCamelCase() 0 3 1
A __construct() 0 2 1
A normalize() 0 3 1
A removeBrackets() 0 3 1
A toLowerCamelCase() 0 3 1
A removeNotWordCharacters() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FRZB\Component\RequestMapper\Helper;
6
7
use JetBrains\PhpStorm\Immutable;
8
9
/** @internal */
10
#[Immutable]
11
final class StringHelper
12
{
13
    private function __construct()
14
    {
15
    }
16
17 5
    public static function toSnakeCase(string $value): string
18
    {
19 5
        return strtolower(preg_replace('/[A-Z]/', '_\\0', lcfirst($value)));
20
    }
21
22 3
    public static function toKebabCase(string $value): string
23
    {
24 3
        return strtolower(preg_replace('/[A-Z]/', '-\\0', lcfirst($value)));
25
    }
26
27 5
    public static function toCamelCase(string $value): string
28
    {
29 5
        return str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $value)));
30
    }
31
32 5
    public static function toLowerCamelCase(string $value): string
33
    {
34 5
        return lcfirst(str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $value))));
35
    }
36
37 17
    public static function contains(string $value, string $subValue): bool
38
    {
39 17
        return str_contains($value, $subValue);
40
    }
41
42 6
    public static function makePrefix(string $prefix, ?string $value = null, string $delimiter = '-'): string
43
    {
44 6
        return $value
45 2
            ? self::normalize($prefix).$delimiter.$value
46 6
            : self::normalize($prefix);
47
    }
48
49 10
    public static function normalize(string $value): string
50
    {
51 10
        return strtolower(preg_replace('/[^a-zA-Z\\d_-]/', '-', $value));
52
    }
53
54 2
    public static function removeBrackets(string $value, array $brackets = ['[', ']']): string
55
    {
56 2
        return str_replace($brackets, '', $value);
57
    }
58
59 20
    public static function removeNotWordCharacters(string $value): string
60
    {
61 20
        return preg_replace('/[^a-zA-Z0-9\\\\]/', '', $value);
62
    }
63
}
64