Passed
Push — main ( a5f538...a74a35 )
by Fractal
03:00
created

StringHelper::removeNotWordCharacters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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