snake2Camel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * Copyright (c) 2019 - present
4
 * updown - helpers.php
5
 * author: Roberto Belotti - [email protected]
6
 * web : robertobelotti.com, github.com/biscolab
7
 * Initial version created on: 15/2/2019
8
 * MIT license: https://github.com/biscolab/updown-php/blob/master/LICENSE
9
 */
10
11
namespace Biscolab\UpDown;
12
13
/**
14
 * @param string $camel
15
 *
16
 * @return string
17
 */
18
function camel2Snake(string $camel): string
19
{
20
21
    return preg_replace('/^_/', '', strtolower(implode('_', preg_split('/(?=[A-Z])/', $camel))));
0 ignored issues
show
Bug introduced by
It seems like preg_split('/(?=[A-Z])/', $camel) can also be of type false; however, parameter $pieces of implode() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

21
    return preg_replace('/^_/', '', strtolower(implode('_', /** @scrutinizer ignore-type */ preg_split('/(?=[A-Z])/', $camel))));
Loading history...
22
}
23
24
/**
25
 * @param string $snake
26
 *
27
 * @return string
28
 */
29
function snake2Camel(string $snake): string
30
{
31
32
    return lcfirst(preg_replace('/_/', '', ucwords($snake, '_')));
33
}