Test Failed
Push — main ( 5edb73...d2cb63 )
by Fractal
02:48
created

StringHelper::toKebabCase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FRZB\Component\RequestMapper\Helper;
6
7
/**
8
 * @internal
9
 */
10
final class StringHelper
11
{
12
    public static function toSnakeCase(string $value): string
13
    {
14
        return strtolower(preg_replace('/[A-Z]/', '_\\0', lcfirst($value)));
15
    }
16
17
    public static function toKebabCase(string $value): string
18
    {
19
        return strtolower(preg_replace('/[A-Z]/', '-\\0', lcfirst($value)));
20
    }
21
22
    public static function toCamelCase(string $value): string
23
    {
24
        return str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $value)));
25
    }
26
27
    public static function toLowerCamelCase(string $value): string
28
    {
29
        return lcfirst(str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $value))));
30
    }
31
32
    public static function contains(string $value, string $subValue): bool
33
    {
34
        return str_contains($value, $subValue);
35
    }
36
37
    public static function makePrefix(string $prefix, ?string $value = null, string $delimiter = '-'): string
38
    {
39
        return $value
40
            ? self::normalize($prefix).$delimiter.$value
41
            : self::normalize($prefix);
42
    }
43
44
    public static function normalize(string $value): string
45
    {
46
        return strtolower(preg_replace('/[^a-zA-Z\\d_-]/', '-', $value));
47
    }
48
49
    public static function removeBrackets(string $value, array $brackets = ['[', ']']): string
50
    {
51
        return str_replace($brackets, '', $value);
52
    }
53
}
54