Passed
Push — feature/initial-implementation ( 77fab8...e556a2 )
by Fike
01:48
created

Strings::snakeToCamel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AmaTeam\ElasticSearch\Utility;
6
7
class Strings
8
{
9
    public static function snakeToCamel(string $input): string
10
    {
11
        $callback = function ($match) {
12
            return mb_strtoupper(mb_substr($match[0], mb_strlen($match[0]) - 1));
13
        };
14
        return preg_replace_callback('~_+\w~u', $callback, trim($input, '_'));
15
    }
16
17
    public static function camelToSnake(string $input): string
18
    {
19
        $callback = function ($match) {
20
            return '_' . $match[0];
21
        };
22
        return mb_strtolower(preg_replace_callback('~(?!^)\p{Lu}+~u', $callback, $input));
23
    }
24
}
25