Issues (18)

src/helpers.php (1 issue)

Labels
Severity
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
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
}