Passed
Push — master ( ad0983...3eb3fa )
by Saulius
01:43
created

strtr()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 7
ccs 3
cts 3
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the sauls/helpers package.
4
 *
5
 * @author    Saulius Vaičeliūnas <[email protected]>
6
 * @link      http://saulius.vaiceliunas.lt
7
 * @copyright 2018
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Sauls\Component\Helper;
14
15
function string_camelize(string $value): string
16
{
17 5
    return \strtr(\ucwords(\strtr($value, ['_' => ' ', '.' => '_ ', '\\' => '_ '])), [' ' => '']);
18
}
19
20
function string_snakeify(string $value): string
21
{
22 3
    \preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $value, $matches);
23 3
    $result = $matches[0];
24 3
    foreach ($result as &$match) {
25 3
        $match = $match === \strtoupper($match) ? \strtolower($match) : \lcfirst($match);
26
    }
27
28 3
    return implode('_', $result);
29
}
30
31
function multi_explode(array $delimiters = ['.'], string $value): array
32
{
33 1
    return \explode($delimiters[0], \str_replace($delimiters, $delimiters[0], $value));
34
}
35
36
function base64_url_encode(string $value): string
37
{
38 1
    return \strtr(\base64_encode($value), '+/', '-_');
39
}
40
41
function base64_url_decode(string $value): string
42
{
43 1
    return base64_decode(\strtr($value, '-_', '+/'));
44
}
45
46
function strtr(string $string, array $parameters): string
47
{
48 20
    foreach ($parameters as $key => $value) {
49 20
        $string = \str_replace($key, $value, $string);
50
    }
51
52 20
    return $string;
53
}
54
55
56