NameNormalizer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
c 1
b 0
f 0
dl 0
loc 15
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A camelCaseToSnakeCase() 0 8 3
1
<?php
2
3
4
namespace Sysbot\Telegram\Common;
5
6
7
/**
8
 * Class NameNormalizer
9
 * @package Sysbot\Telegram\Common
10
 */
11
class NameNormalizer
12
{
13
14
    /**
15
     * @param string $input
16
     * @return string
17
     */
18
    public static function camelCaseToSnakeCase(string $input): string
19
    {
20
        preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches);
21
        $ret = $matches[0];
22
        foreach ($ret as &$match) {
23
            $match = $match == strtoupper($match) ? strtolower($match) : lcfirst($match);
24
        }
25
        return implode('_', $ret);
26
    }
27
28
}