StringHelper::makePrefix()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 3
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 2
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
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